IPEndPoint.Port 属性

获取或设置终结点的端口号。

**命名空间:**System.Net
**程序集:**System(在 system.dll 中)

语法

声明
Public Property Port As Integer
用法
Dim instance As IPEndPoint
Dim value As Integer

value = instance.Port

instance.Port = value
public int Port { get; set; }
public:
property int Port {
    int get ();
    void set (int value);
}
/** @property */
public int get_Port ()

/** @property */
public void set_Port (int value)
public function get Port () : int

public function set Port (value : int)

属性值

介于 MinPortMaxPort 之间的整数值,指示终结点的端口号。

异常

异常类型 条件

ArgumentOutOfRangeException

为设置操作指定的值小于 MinPort 或大于 MaxPort

示例

下面的示例使用 Port 属性设置 EndPoint 的 TCP 端口号。

Private Shared Sub displayEndpointInfo(ByVal endpoint As IPEndPoint)
  Console.WriteLine("Endpoint Address : " + endpoint.Address.ToString())
  Console.WriteLine("Endpoint AddressFamily : " + endpoint.AddressFamily.ToString())
  Console.WriteLine("Endpoint Port : " + endpoint.Port.ToString())
  Console.WriteLine("Endpoint ToString() : " + endpoint.ToString())

  Console.WriteLine("Press any key to continue.")
  Console.ReadLine()
End Sub 'displayEndpointInfo
private static void displayEndpointInfo(IPEndPoint endpoint)
{
  Console.WriteLine("Endpoint.Address : " + endpoint.Address);
  Console.WriteLine("Endpoint.AddressFamily : " + endpoint.AddressFamily);
  Console.WriteLine("Endpoint.Port : " + endpoint.Port);
  Console.WriteLine("Endpoint.ToString() : " + endpoint.ToString());

  Console.WriteLine("Press any key to continue.");
  Console.ReadLine();
}
void displayEndpointInfo( IPEndPoint^ endpoint )
{
   Console::WriteLine( "Endpoint->Address : {0}", endpoint->Address );
   Console::WriteLine( "Endpoint->AddressFamily : {0}", endpoint->AddressFamily );
   Console::WriteLine( "Endpoint->Port : {0}", endpoint->Port );
   Console::WriteLine( "Endpoint.ToString() : {0}", endpoint );
   Console::WriteLine( "Press any key to continue." );
   Console::ReadLine();
}
private static void DisplayEndpointInfo(IPEndPoint endpoint)
{
    Console.WriteLine(("Endpoint.Address : " + endpoint.get_Address()));
    Console.WriteLine(("Endpoint.AddressFamily : " 
        + endpoint.get_AddressFamily()));
    Console.WriteLine(("Endpoint.Port : " + endpoint.get_Port()));
    Console.WriteLine(("Endpoint.ToString() : " 
        + endpoint.ToString()));
    Console.WriteLine("Press any key to continue.");
    Console.ReadLine();
} //DisplayEndpointInfo

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

.NET Compact Framework

受以下版本支持:2.0、1.0

请参见

参考

IPEndPoint 类
IPEndPoint 成员
System.Net 命名空间