我有一个变量,该变量具有要切换的值并根据这些值执行操作。这是我目前正在做的事情:
switch(myvalue)
{
case "action1_category1":
doAction1();
break;
case "action2_category1":
doAction2();
break;
case "action3_category1":
doAction3();
break;
case "action4_category2":
doAction4();
break;
case "action5_category2":
doAction5();
break;
case "action6_category2":
doAction6();
break;
...
}
所以,我在想为什么不将变量分为两类,并这样做:
if(myvalue.endsWith("category1")
{
switch(myvalue)
{
case "action1_category1":
doAction1();
break;
case "action2_category1":
doAction2();
break;
case "action3_category1":
doAction3();
break;
...
}
}
else
{
switch(myvalue)
{
case "action4_category2":
doAction4();
break;
case "action5_category2":
doAction5();
break;
case "action6_category2":
doAction6();
break;
...
}
}
这种新方法会提高还是降低我的表现?谢谢。