IPAddress.TryParse IPAddress.TryParse IPAddress.TryParse IPAddress.TryParse Method

Definition

Overloads

TryParse(String, IPAddress) TryParse(String, IPAddress) TryParse(String, IPAddress) TryParse(String, IPAddress)

Determines whether a string is a valid IP address.

TryParse(ReadOnlySpan<Char>, IPAddress) TryParse(ReadOnlySpan<Char>, IPAddress) TryParse(ReadOnlySpan<Char>, IPAddress) TryParse(ReadOnlySpan<Char>, IPAddress)

TryParse(String, IPAddress) TryParse(String, IPAddress) TryParse(String, IPAddress) TryParse(String, IPAddress)

Determines whether a string is a valid IP address.

public:
 static bool TryParse(System::String ^ ipString, [Runtime::InteropServices::Out] System::Net::IPAddress ^ % address);
public static bool TryParse (string ipString, out System.Net.IPAddress address);
static member TryParse : string *  -> bool
Public Shared Function TryParse (ipString As String, ByRef address As IPAddress) As Boolean

Parameters

ipString
String String String String

The string to validate.

address
IPAddress IPAddress IPAddress IPAddress

The IPAddress version of the string.

Returns

true if ipString was able to be parsed as an IP address; otherwise, false.

Exceptions

Remarks

Note that this method accepts as valid an ipString value that can be parsed as an Int64, and then treats that Int64 as the long value of an IP address in network byte order, similar to the way that the IPAddress constructor does. This means that this method returns true if the Int64 is parsed successfully, even if it represents an address that's not a valid IP address. For example, if ipString is "1", this method returns true even though "1" (or 0.0.0.1) is not a valid IP address and you might expect this method to return false. Fixing this bug would break existing apps, so the current behavior will not be changed. Your code can avoid this behavior by ensuring that it only uses this method to parse IP addresses in dotted-decimal format.

TryParse(ReadOnlySpan<Char>, IPAddress) TryParse(ReadOnlySpan<Char>, IPAddress) TryParse(ReadOnlySpan<Char>, IPAddress) TryParse(ReadOnlySpan<Char>, IPAddress)

public:
 static bool TryParse(ReadOnlySpan<char> ipString, [Runtime::InteropServices::Out] System::Net::IPAddress ^ % address);
public static bool TryParse (ReadOnlySpan<char> ipString, out System.Net.IPAddress address);
static member TryParse : ReadOnlySpan<char> *  -> bool
Public Shared Function TryParse (ipString As ReadOnlySpan(Of Char), ByRef address As IPAddress) As Boolean

Parameters

ipString
ReadOnlySpan<Char>

Returns

Applies to