简体   繁体   English

使用串行通信C#时获取端口列表

[英]Getting list of ports when using serial communication C#

I am aware of the syntax used to get the port names 我知道用于获取端口名称的语法

string[] ports = SerialPort.GetPortNames();

The output is not quite as expected. 输出不完全符合预期。 When I go on to print the strings, the output is; 当我继续打印字符串时,输出为:

System.String[]

I am probably missing something. 我可能错过了一些东西。 Kindly help... 请帮助...

You are printing the array object not the strings in the array: 您正在打印数组对象而不是数组中的字符串:

for(int i=0; i<ports.Length; i++)
{
     Console.WriteLine(ports[i]);
}

Or use: 或使用:

foreach(String port in ports)
{
     Console.WriteLine(port);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM