February 12, 2016
How to Get HostName in C#/CSharp
To get host name of the local computer, we make use of GetHostName() method which resides in Dns class. Dns class is part of System.Net space. Example is given below.
using System; using System.Net; namespace Hello_World { class Program { static void Main(string[] args) { string hostname = Dns.GetHostName(); Console.WriteLine(hostname); } } }