共用方式為


PortCollection.Add(Port) 方法

定義

將指定的 Port 加入至 PortCollection 的結尾。

public:
 int Add(System::Web::Services::Description::Port ^ port);
public int Add (System.Web.Services.Description.Port port);
member this.Add : System.Web.Services.Description.Port -> int
Public Function Add (port As Port) As Integer

參數

port
Port

要加入至集合的 Port

傳回

Int32

已加入 port 參數處的以零起始的索引。

範例

myPortCollection = myService->Ports;
Port^ myNewPort = myPortCollection[ 0 ];
myPortCollection->Remove( myNewPort );

// Display the number of ports.
Console::WriteLine( "\nTotal number of ports before adding a new port : {0}", myService->Ports->Count );

// Add a new port.
myPortCollection->Add( myNewPort );

// Display the number of ports after adding a port.
Console::WriteLine( "Total number of ports after adding a new port : {0}", myService->Ports->Count );

myPortCollection = myService.Ports;
Port myNewPort = myPortCollection[0];

myPortCollection.Remove(myNewPort);

// Display the number of ports.
Console.WriteLine("\nTotal number of ports before"
   + " adding a new port : " +  myService.Ports.Count);

// Add a new port.
myPortCollection.Add(myNewPort);

// Display the number of ports after adding a port.
Console.WriteLine("Total number of ports after"
   + " adding a new port : " + myService.Ports.Count);
myPortCollection = myService.Ports
Dim myNewPort As Port = myPortCollection(0)
myPortCollection.Remove(myNewPort)

' Display the number of ports.
Console.WriteLine(ControlChars.NewLine & _
   "Total number of ports before " & _
   "adding a new port : " & _
   myService.Ports.Count.ToString)

' Add a new port.
myPortCollection.Add(myNewPort)

' Display the number of ports after adding a port.
Console.WriteLine("Total number of ports after " & _
   "adding a new port : " & _
   myService.Ports.Count.ToString)

適用於