How to get the Computer Name in C# ?

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