string liquidClass = string.Empty;
switch (cmbLiquidClass.Text)
{
case "LiquidClass1":
liquidClass = Settings.Default.LiquidClass1;
break;
case "LiquidClass2":
liquidClass = Settings.Default.LiquidClass2;
break;
case "LiquidClass3":
liquidClass = Settings.Default.LiquidClass3;
break;
case "LiquidClass4":
liquidClass = Settings.Default.LiquidClass4;
break;
case "LiquidClass5":
liquidClass = Settings.Default.LiquidClass5;
break;
case "LiquidClass6":
liquidClass = Settings.Default.LiquidClass6;
break;
case "LiquidClass7":
liquidClass = Settings.Default.LiquidClass7;
break;
case "LiquidClass8":
liquidClass = Settings.Default.LiquidClass8;
break;
case "LiquidClass9":
liquidClass = Settings.Default.LiquidClass9;
break;
}
試圖獲取當前類的內容。由於字符串的工作方式(行爲類似於值類型),我無法使用字典。有什麼方法可以重構這個,以便它不需要這麼多的線來找到所選的液體類?如何重構這個switch語句?
使用一個陣列和一個for循環? – ATaylor
_Why_你不能使用'Dictionary'嗎? –
@ATaylor:難道你不能在Settings文件中存儲集合嗎? –