Export (0) Print
Expand All

IPAddress.Parse Method

Converts an IP address string to an IPAddress instance.

Namespace:  System.Net
Assembly:  System (in System.dll)

static member Parse : 
        ipString:string -> IPAddress

Parameters

ipString
Type: System.String

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

Return Value

Type: System.Net.IPAddress
An IPAddress instance.

ExceptionCondition
ArgumentNullException

ipString is a null reference (Nothing in Visual Basic).

FormatException

ipString is not a valid IP address.

The static Parse method creates an IPAddress instance from an IP address expressed in dotted-quad notation for IPv4 and in colon-hexadecimal notation for IPv6.

The number of parts (each part is separated by a period) in ipString determines how the IP address is constructed. A one part address is stored directly in the network address. A two part address, convenient for specifying a class A address, puts the leading part in the first byte and the trailing part in the right-most three bytes of the network address. A three part address, convenient for specifying a class B address, puts the first part in the first byte, the second part in the second byte, and the final part in the right-most two bytes of the network address. For example:

Number of parts and example ipString

IPv4 address for IPAddress

1 -- "65536"

0.0.255.255

2 -- "20.2"

20.0.0.2

2 -- "20.65535"

20.0.255.255

3 -- "128.1.2"

128.1.0.2

The following code converts a string that contains an IP address, in dotted-quad notation for IPv4 or in colon-hexadecimal notation for IPv6, into an instance of the IPAddress class. Then it uses the overloaded ToString method to display the address in standard notation.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone 8, Silverlight 8.1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft