How to get the Computer Name in C# ?

Published on February 8, 2016 by abundantcode

Filed under C#

Last modified February 8, 2016

Print this page

rate 1 star rate 2 star rate 3 star rate 4 star rate 5 star
Your rating: none, Average: 0 (0 votes)

This article have been viewed 3941 times

When working on a Winforms or Console application using C# , sometimes you might need to get the computer name where the application is running.

How to get the Computer Name in C# ?

To retrieve the computer name , one can use the System.Environment.MachineName property as shown below.

using System;
namespace ACCode
{
    class Program
    {
        static void Main(string[] args)
        {
            var computerName = System.Environment.MachineName;
            Console.WriteLine(computerName);
            Console.ReadLine();
        }
    } 
}

Leave a Comment


x

You might be Interested in these Posts

How to disable editing of items in a combo box in c#?

When working in Win forms using C# and especially when you use the combo box , you would have notice...

Creating Button in XAML in WPF and Windows Store App

Below is a sample Xaml code that is used to create a button in WPF and Windows Store App. <Butto...

How to Pass enum as command parameter in Xaml ?

Below is a sample code snippet demonstrating how to pass enum as command parameter in Xaml. How to ...