Uredi

Deli z drugimi prek


IPEndPoint.TryParse Method

Definition

Overloads

TryParse(ReadOnlySpan<Char>, IPEndPoint)

Tries to convert an IP network endpoint (address and port) represented as a read-only span to its IPEndPoint equivalent, and returns a value that indicates whether the conversion succeeded.

TryParse(String, IPEndPoint)

Tries to convert an IP network endpoint (address and port) represented as a string to its IPEndPoint equivalent, and returns a value that indicates whether the conversion succeeded.

Remarks

The number of parts (each part is separated by a period) in s determines how the endpoint's 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 s IPv4 address for IPEndPoint.Address Port
1 -- "1" 0.0.0.1 0
2 -- "20.2:80" 20.0.0.2 80
2 -- "20.65535:23" 20.0.255.255 23
3 -- "128.1.2:443" 128.1.0.2 443

Important

Note that this method accepts as valid a 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 s 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.

Literal IPv6 addresses require to be enclosed in square brackets [] when passing an endpoint that specifies a port number; otherwise, square braces are not mandatory.

TryParse(ReadOnlySpan<Char>, IPEndPoint)

Source:
IPEndPoint.cs
Source:
IPEndPoint.cs
Source:
IPEndPoint.cs

Tries to convert an IP network endpoint (address and port) represented as a read-only span to its IPEndPoint equivalent, and returns a value that indicates whether the conversion succeeded.

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

Parameters

s
ReadOnlySpan<Char>

The IP endpoint to validate.

result
IPEndPoint

When this method returns, the IPEndPoint version of s.

Returns

true if s can be parsed as an IP endpoint; otherwise, false.

Applies to

TryParse(String, IPEndPoint)

Source:
IPEndPoint.cs
Source:
IPEndPoint.cs
Source:
IPEndPoint.cs

Tries to convert an IP network endpoint (address and port) represented as a string to its IPEndPoint equivalent, and returns a value that indicates whether the conversion succeeded.

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

Parameters

s
String

The IP endpoint to validate.

result
IPEndPoint

When this method returns, the IPEndPoint version of s.

Returns

true if s can be parsed as an IP endpoint; otherwise, false.

Applies to