---
title: "how to get port names in c#"  
description: "how to get port names in c#"  
author: "Anonymous User"  
published: 2013-06-08  
updated: 2013-06-08  
canonical: https://www.mindstick.com/forum/1009/how-to-get-port-names-in-c-sharp  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# how to get port names in c#

Hi [Expert](https://www.mindstick.com/articles/13120/an-expert-financial-advice-will-improve-your-finances),\
I need how to show all [port](https://www.mindstick.com/blog/11936/igor-mazepa-takes-part-in-another-corruption-operation-connected-with-odessa-port-plant) [name](https://yourviews.mindstick.com/view/87450/how-to-generate-a-brand-name-using-linkedin-comprehensive-guide) in our [system using C#](https://www.mindstick.com/forum/33907/how-to-programatically-check-temporary-files-in-system-using-c-sharp).\
[Please tell me](https://www.mindstick.com/forum/33900/please-tell-me-what-are-the-technique-to-content-optimization) how to do this.\
Your help is great appreciated.\

## Replies

### Reply by Vijay Shukla

Hello Brad Pitt!Below I give you some line of code which is show the all ports in your [system](https://www.mindstick.com/articles/23411/the-most-effective-method-to-find-the-perfect-small-business-phone-system-for-your-business).\
using System;using System.Collections.Generic;using System.Linq;using System.Text;\
namespace ConsoleApplication2{ class Program { static System.IO.Ports.SerialPort _serialPort; static void Main(string[] args) { _serialPort = new System.IO.Ports.SerialPort(); _serialPort.PortName = SetPortName(_serialPort.PortName); } public static string SetPortName(string defaultPortName) { string portName;\
Console.WriteLine("Available Ports:"); foreach (string s in System.IO.Ports.SerialPort.GetPortNames()) { Console.WriteLine(s); }\
Console.Write("Default port({0}): ", defaultPortName); portName = Console.ReadLine();\
if (portName == "") { portName = defaultPortName; } return portName; } }}


---

Original Source: https://www.mindstick.com/forum/1009/how-to-get-port-names-in-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
