ScottSummers
ScottSummers

Reputation: 370

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...

Upvotes: 0

Views: 833

Answers (1)

user7351608
user7351608

Reputation: 451

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

Upvotes: 1

Related Questions