Get Local Computer Name in C#

Published on Thursday, January 20, 2011
c c#

Here we got 4 ways to get local computer name:

1: string name = Environment.MachineName;

2: string name = System.Net.Dns.GetHostName();

3: string name = System.Windows.Forms.SystemInformation.ComputerName;

4: string name = System.Environment.GetEnvironmentVariable(“COMPUTERNAME”);