Bewerken

Delen via


IPEndPoint.Parse Method

Definition

Overloads

Parse(ReadOnlySpan<Char>)

Converts an IP network endpoint (address and port) represented as a read-only span to an IPEndPoint instance.

Parse(String)

Converts an IP network endpoint (address and port) represented as a string to an IPEndPoint instance.

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.

Parse(ReadOnlySpan<Char>)

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

Converts an IP network endpoint (address and port) represented as a read-only span to an IPEndPoint instance.

public:
 static System::Net::IPEndPoint ^ Parse(ReadOnlySpan<char> s);
public static System.Net.IPEndPoint Parse (ReadOnlySpan<char> s);
static member Parse : ReadOnlySpan<char> -> System.Net.IPEndPoint
Public Shared Function Parse (s As ReadOnlySpan(Of Char)) As IPEndPoint

Parameters

s
ReadOnlySpan<Char>

A read-only span that contains an IP endpoint in dotted-quad notation or network byte order for IPv4 and in colon-hexadecimal notation for IPv6.

Returns

The object representation of an IP network endpoint.

Exceptions

s is not a valid IP endpoint.

Applies to

Parse(String)

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

Converts an IP network endpoint (address and port) represented as a string to an IPEndPoint instance.

public:
 static System::Net::IPEndPoint ^ Parse(System::String ^ s);
public static System.Net.IPEndPoint Parse (string s);
static member Parse : string -> System.Net.IPEndPoint
Public Shared Function Parse (s As String) As IPEndPoint

Parameters

s
String

A string that contains an IP endpoint in dotted-quad notation or network byte order for IPv4 and in colon-hexadecimal notation for IPv6.

Returns

The object representation of an IP network endpoint.

Exceptions

s is not a valid IP endpoint.

Applies to