C# IPAddress Parse

Description

IPAddress Parse Converts an IP address string to an IPAddress instance.

Syntax

IPAddress.Parse has the following syntax.


public static IPAddress Parse(
  string ipString
)

Parameters

IPAddress.Parse has the following parameters.

  • ipString - A string that contains an IP address in dotted-quad notation for IPv4 and in colon-hexadecimal notation for IPv6.

Returns

IPAddress.Parse method returns An IPAddress instance.

Example


using System;//from   w w  w. ja  va  2  s. c om
using System.Net;

class ParseAddress
{

  private static void Main(string[] args) 
  {
      string ipAddress = "127.0.0.1";
    try
    {
      IPAddress address = IPAddress.Parse(ipAddress);
      Console.WriteLine("Parsing your input string: " + "\"" + ipAddress + "\"" + " produces this address (shown in its standard notation): "+ address.ToString());
    }
    catch(FormatException e)
    {
      Console.WriteLine("FormatException caught!!!");
      Console.WriteLine("Source : " + e.Source);
      Console.WriteLine("Message : " + e.Message);
    }

    catch(Exception e)
    {
      Console.WriteLine("Exception caught!!!");
      Console.WriteLine("Source : " + e.Source);
      Console.WriteLine("Message : " + e.Message);
    }

   }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Net »




Cookie
Dns
IPAddress
IPEndPoint
IPHostEntry
WebClient