DnsEndPoint 构造函数

定义

初始化 DnsEndPoint 类的新实例。Initializes a new instance of the DnsEndPoint class.

重载

DnsEndPoint(String, Int32)

用主机名或 IP 地址和端口号的字符串表示形式初始化 DnsEndPoint 类的新实例。Initializes a new instance of the DnsEndPoint class with the host name or string representation of an IP address and a port number.

DnsEndPoint(String, Int32, AddressFamily)

用主机名或 IP 地址、端口号和地址族的字符串表示形式初始化 DnsEndPoint 类的新实例。Initializes a new instance of the DnsEndPoint class with the host name or string representation of an IP address, a port number, and an address family.

DnsEndPoint(String, Int32)

用主机名或 IP 地址和端口号的字符串表示形式初始化 DnsEndPoint 类的新实例。Initializes a new instance of the DnsEndPoint class with the host name or string representation of an IP address and a port number.

public:
 DnsEndPoint(System::String ^ host, int port);
public DnsEndPoint (string host, int port);
new System.Net.DnsEndPoint : string * int -> System.Net.DnsEndPoint
Public Sub New (host As String, port As Integer)

参数

host
String

主机名或 IP 地址的字符串表示形式。The host name or a string representation of the IP address.

port
Int32

与 address 关联的端口号,或为 0 以指定任何可用端口。The port number associated with the address, or 0 to specify any available port. port 以主机顺序排列。port is in host order.

例外

host 参数包含空字符串。The host parameter contains an empty string.

host 参数为 nullThe host parameter is a null.

port 小于 MinPortport is less than MinPort.

- 或 --or- port 大于 MaxPortport is greater than MaxPort.

注解

DnsEndPoint(String, Int32)构造函数可用于 DnsEndPoint 使用主机名或表示 IP 地址和端口的字符串来初始化类。The DnsEndPoint(String, Int32) constructor can be used to initialize a DnsEndPoint class using either a host name or a string that represents an IP address and a port. 此构造函数将 AddressFamily 属性设置为 UnknownThis constructor sets the AddressFamily property to Unknown.

将此构造函数用于主机名而不是 IP 地址的字符串表示形式时,的地址族即使在 DnsEndPoint 使用后也会保留 UnknownWhen using this constructor with a host name rather than a string representation of an IP address, the address family of the DnsEndPoint will remain Unknown even after use. AddressFamily Socket 通过调用方法创建的任何的属性 ConnectAsync 将是可成功建立连接的第一个地址的地址系列 (不一定要解析) 的第一个地址。The AddressFamily property of any Socket that is created by calls to the ConnectAsync method will be the address family of the first address to which a connection can be successfully established (not necessarily the first address to be resolved).

适用于

DnsEndPoint(String, Int32, AddressFamily)

用主机名或 IP 地址、端口号和地址族的字符串表示形式初始化 DnsEndPoint 类的新实例。Initializes a new instance of the DnsEndPoint class with the host name or string representation of an IP address, a port number, and an address family.

public:
 DnsEndPoint(System::String ^ host, int port, System::Net::Sockets::AddressFamily addressFamily);
public DnsEndPoint (string host, int port, System.Net.Sockets.AddressFamily addressFamily);
new System.Net.DnsEndPoint : string * int * System.Net.Sockets.AddressFamily -> System.Net.DnsEndPoint
Public Sub New (host As String, port As Integer, addressFamily As AddressFamily)

参数

host
String

主机名或 IP 地址的字符串表示形式。The host name or a string representation of the IP address.

port
Int32

与 address 关联的端口号,或为 0 以指定任何可用端口。The port number associated with the address, or 0 to specify any available port. port 以主机顺序排列。port is in host order.

addressFamily
AddressFamily

AddressFamily 值之一。One of the AddressFamily values.

例外

host 参数包含空字符串。The host parameter contains an empty string.

- 或 --or- addressFamilyUnknownaddressFamily is Unknown.

host 参数为 nullThe host parameter is a null.

port 小于 MinPortport is less than MinPort.

- 或 --or- port 大于 MaxPortport is greater than MaxPort.

注解

DnsEndPoint(String, Int32, AddressFamily)构造函数可用于 DnsEndPoint 使用主机名或表示 IP 地址、端口和地址族的字符串来初始化类。The DnsEndPoint(String, Int32, AddressFamily) constructor can be used to initialize a DnsEndPoint class using either a host name or a string that represents an IP address, a port, and an address family.

使用具有主机名而不是 IP 地址的字符串表示形式的构造函数时,地址族会将 DNS 解析限制为首选指定地址族值的地址。When using the constructor with a host name rather than a string representation of an IP address, the address family restricts DNS resolution to prefer addresses of the specified address family value. 将构造函数与指定为的地址族结合使用时 Unknown ,的地址族 DnsEndPoint 仍将保留 UnknownWhen using the constructor with the address family specified as Unknown, the address family of the DnsEndPoint will remain Unknown even after use. AddressFamily Socket 通过调用方法创建的任何的属性 ConnectAsync 将是可成功建立连接的第一个地址的地址系列 (不一定要解析) 的第一个地址。The AddressFamily property of any Socket that is created by calls to the ConnectAsync method will be the address family of the first address to which a connection can be successfully established (not necessarily the first address to be resolved).

适用于