我有这行代码很长,我想知道这些代码是否可以从中转换
if(BtnInteracted == "New"){
if(sample_1.SaveSlotNumber == "1"){
if(){
}
else{
}
}
else if(sample_1.SaveSlotNumber == "2"){
if(){
}
else{
}
}
else if(sample_1.SaveSlotNumber == "3"){
if(){
}
else{
}
}
}
else if (BtnInteracted == "Con"){
if(sample_1.SaveSlotNumber == "1"){
if(){
}
else{
}
}
else if(sample_1.SaveSlotNumber == "2"){
if(){
}
else{
}
}
else if(sample_1.SaveSlotNumber == "3"){
if(){
}
else{
}
}
}
对此。
switch(BtnInteracted){
case "New": switch (sample_1.SaveSlotNumber){
case "1": //if() else() statement;
case "2": //if() else() statement;
case "3": //if() else() statement;
} break;
case "Con": switch (sample_1.SaveSlotNumber){
case "1": //if() else() statement;
case "2": //if() else() statement;
case "3": //if() else() statement;
} break;
}
甚至可以制作此代码还是我的原始代码是我唯一的选择?感谢您的回复!