C# 代码优化:在字典中查找特定值并赋值给变量
//如果输入的strPN等于'NFL-IR-500-17-FH' else if (strPN == 'NFL-IR-500-17-FH') { int index = 0; //在NFL_IR_500_17_FH字典中查找mode对应的值 while (index < NFL_IR_500_17_FH.Count && mode != NFL_IR_500_17_FH.Keys.ElementAt(index)) index++; //如果找到了对应的值 if (index < NFL_IR_500_17_FH.Count) { //将对应的值赋给width变量 width = NFL_IR_500_17_FH.Values.ElementAt(index).ToString(); return null; } //如果没有找到对应的值 else { //将width变量赋为空字符串 width = ""; return null; } } //需要优化的部分
原文地址: https://www.cveoy.top/t/topic/mJe0 著作权归作者所有。请勿转载和采集!