C# Dns GetHostName

Description

Dns GetHostName Gets the host name of the local computer.

Syntax

Dns.GetHostName has the following syntax.


public static string GetHostName()

Returns

Dns.GetHostName method returns A string that contains the DNS host name of the local computer.

Example

The following example uses the GetHostName method to obtain the host name of the local computer.


//  w  w  w . j av  a 2 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 »
    System.Net »




Cookie
Dns
IPAddress
IPEndPoint
IPHostEntry
WebClient