IPAddress.Parse Method
Microsoft Silverlight will reach end of support after October 2021. Learn more.
Converts an IP address string to an IPAddress instance.
Namespace: System.Net
Assembly: System.Net (in System.Net.dll)
Syntax
'Declaration
Public Shared Function Parse ( _
ipString As String _
) As IPAddress
public static IPAddress Parse(
string ipString
)
Parameters
- ipString
Type: System.String
A string that contains an IP address in dotted-quad notation for IPv4 or an IP address in colon-hexadecimal notation for IPv6.
Return Value
Type: System.Net.IPAddress
An IPAddress instance.
Exceptions
Exception | Condition |
---|---|
ArgumentNullException | The ipString parameter is nulla null reference (Nothing in Visual Basic). |
FormatException | The ipString parameter is not a valid IP address. |
Remarks
The static Parse method creates an IPAddress instance from an IP address expressed in dotted-quad notation for IPv4 or an IP address expressed in colon-hexadecimal notation for IPv6.
For IPv4, 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 |
For IPv6, the Scope Id is also parsed if this present in the ipString parameter.
Version Information
Silverlight
Supported in: 5, 4, 3
Silverlight for Windows Phone
Supported in: Windows Phone OS 7.1
Platforms
For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.