This documentation is archived and is not being maintained.
PortCollection.Add Method
.NET Framework 1.1
Adds the specified Port to the end of the PortCollection.
[Visual Basic] Public Function Add( _ ByVal port As Port _ ) As Integer [C#] public int Add( Port port ); [C++] public: int Add( Port* port ); [JScript] public function Add( port : Port ) : int;
Parameters
- port
- The Port to add to the collection.
Return Value
The zero-based index where the port parameter has been added.
Example
[Visual Basic] 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) [C#] 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); [C++] myPortCollection = myService->Ports; Port* myNewPort = myPortCollection->Item[0]; myPortCollection->Remove(myNewPort); // Display the number of ports. Console::WriteLine(S"\nTotal number of ports before adding a new port : {0}", __box(myService->Ports->Count)); // Add a new port. myPortCollection->Add(myNewPort); // Display the number of ports after adding a port. Console::WriteLine(S"Total number of ports after adding a new port : {0}", __box(myService->Ports->Count));
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family
See Also
PortCollection Class | PortCollection Members | System.Web.Services.Description Namespace
Show: