C# 判断并口、串口或混合类型 - 代码示例与优化
string[] strArray = { ".MOMODE\r\n", ".APMODE\r\n", ".PWMODE\r\n", ".FQMODE\r\n", ".LMMODE\r\n" };
List
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("混合"); }
原文地址: https://www.cveoy.top/t/topic/nggP 著作权归作者所有。请勿转载和采集!