简体   繁体   中英

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);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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