[英]Getting list of ports when using serial communication C#
我知道用於獲取端口名稱的語法
string[] ports = SerialPort.GetPortNames();
輸出不完全符合預期。 當我繼續打印字符串時,輸出為:
System.String[]
我可能錯過了一些東西。 請幫助...
您正在打印數組對象而不是數組中的字符串:
for(int i=0; i<ports.Length; i++)
{
Console.WriteLine(ports[i]);
}
或使用:
foreach(String port in ports)
{
Console.WriteLine(port);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.