string[] strArray = { ".MOMODE\r\n", ".APMODE\r\n", ".PWMODE\r\n", ".FQMODE\r\n", ".LMMODE\r\n" }; List listInt = new List(); for (int i = 0; i < strArray.Length; i++) { int temp = laserPort.Read2(strArray[i]).RetVal; listInt.Add(temp); }

if (listInt.All(x => x == 0)) { Console.WriteLine("并口"); } else if (listInt.All(x => x == 1)) { Console.WriteLine("串口"); } else { Console.WriteLine("混合"); } //优化 if (listInt.Distinct().Count() == 1) { Console.WriteLine(listInt[0] == 0 ? "并口" : "串口"); } else { Console.WriteLine("混合"); }

C# 判断并口、串口或混合类型 - 代码示例与优化

原文地址: https://www.cveoy.top/t/topic/nggP 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录