TryParse Method
Collapse the table of content
Expand the table of content

IPAddress.TryParse Method

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Determines whether a string is a valid IP address.

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

'Declaration
Public Shared Function TryParse ( _
	ipString As String, _
	<OutAttribute> ByRef address As IPAddress _
) As Boolean

Parameters

ipString
Type: System.String
The string to validate.
address
Type: System.Net.IPAddress %
The IPAddress version of the string.

Return Value

Type: System.Boolean
true if ipString is a valid IP address; otherwise, false.

ExceptionCondition
ArgumentException

ipString could not be parsed as an IP address.

ArgumentNullException

ipString is Nothing.

FormatException

ipString is not a valid IP address.

This method tries to parse 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 and validated if this present in the ipString parameter.

Windows Phone OS

Supported in: 8.1, 8.0, 7.1

Windows Phone

Show:
© 2017 Microsoft