How to get the serial port names of my computer in C#

1 Answer

0 votes
using System;
using System.IO.Ports;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            // example 1
            string[] theSerialPortNames = SerialPort.GetPortNames();
            foreach (string s in theSerialPortNames)
            {
                Console.WriteLine(s);
            }

            // example 2
            foreach (string s in SerialPort.GetPortNames())
            {
                Console.WriteLine(s.ToString());
            }
        }
    }
}


answered Apr 9, 2014 by avibootz

Related questions

1 answer 259 views
259 views asked Apr 8, 2014 by avibootz
1 answer 130 views
130 views asked Jan 14, 2017 by avibootz
1 answer 174 views
174 views asked Jan 14, 2017 by avibootz
1 answer 160 views
160 views asked Jan 14, 2017 by avibootz
1 answer 192 views
192 views asked Jan 14, 2017 by avibootz
...