当前位置: 动力学知识库 > 问答 > 编程问答 >

wpf - 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);
}
分享给朋友:
您可能感兴趣的文章:
随机阅读: