IPAddress.TryParse Method
Definition
Overloads
| TryParse(ReadOnlySpan<Char>, IPAddress) |
Determines whether the specified byte span represents a valid IP address. |
| TryParse(String, IPAddress) |
Determines whether a string is a valid IP address. |
TryParse(ReadOnlySpan<Char>, IPAddress)
Determines whether the specified byte span represents a valid IP address.
public:
static bool TryParse(ReadOnlySpan<char> ipSpan, [Runtime::InteropServices::Out] System::Net::IPAddress ^ % address);
public:
static bool TryParse(ReadOnlySpan<char> ipString, [Runtime::InteropServices::Out] System::Net::IPAddress ^ % address);
public static bool TryParse (ReadOnlySpan<char> ipSpan, out System.Net.IPAddress? address);
public static bool TryParse (ReadOnlySpan<char> ipString, out System.Net.IPAddress address);
static member TryParse : ReadOnlySpan<char> * IPAddress -> bool
static member TryParse : ReadOnlySpan<char> * IPAddress -> bool
Public Shared Function TryParse (ipSpan As ReadOnlySpan(Of Char), ByRef address As IPAddress) As Boolean
Public Shared Function TryParse (ipString As ReadOnlySpan(Of Char), ByRef address As IPAddress) As Boolean
Parameters
- ipStringipSpan
- ReadOnlySpan<Char>
The byte span to validate.
Returns
true if ipString was able to be parsed as an IP address; otherwise, false.
Applies to
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);
public static bool TryParse (string? ipString, out System.Net.IPAddress? address);
static member TryParse : string * IPAddress -> bool
Public Shared Function TryParse (ipString As String, ByRef address As IPAddress) As Boolean
Parameters
- ipString
- String
The string to validate.
Returns
true if ipString was able to be parsed as an IP address; otherwise, false.
Exceptions
ipString is null.
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.