refactoring switch statements

Hi all ,

is there a way to minimize a large switch statement by using dynamic variable ,

my job look like this :

static void Job12(Args _args){

EcoResCategory a,b;

Container res;

str s1,s2,s3,s4,s5,s6;

SELECT firstonly a where a.CategoryHierarchy == 45677731554 ;

while select b order by b.Level asc

where b.CategoryHierarchy == a.CategoryHierarchy

&& b.NestedSetLeft <= a.NestedSetLeft

&& b.NestedSetRight >= a.NestedSetLeft

{

switch(b.Level) {

case 1:

s1 = = b.Name;

break;

case 2:

s1 = = b.Name;

break;

case 3:

s1 = = b.Name;

break;

case 4:

s1 = = b.Name;

break;

case 5:

s1 = = b.Name;

break;

case 6:

s1 = = b.Name;

break;

}

}

res = [s1,s2,s3,s4,s5,s6]

}

Your code doesn’t make sense. You probably wanted to assigned values to s1 - s6 variables, but your code doesn’t do that.

Unfortunately you didn’t tell us what you want to achieve, so we can only guess. If you simply want to create a container from returned names (and you don’t need any additional processing, such as handling of missing levels), replace your switch statement with this:

i++;
conIns(res, i, b.Name);

and then return res.