Get the host name of the local computer in CSharp

Description

The following code shows how to get the host name of the local computer.

Example


/*from  ww  w  .  jav a2 s . co  m*/
using System;
using System.Net;
using System.Net.Sockets;

public class Example
{
   public static void Main()
   {
         String hostName = Dns.GetHostName();
         Console.WriteLine("Computer name :" + hostName);
    
   }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Network »




IP
Web Client