This documentation is archived and is not being maintained.

PortCollection.Contains Method

Returns a value indicating whether the specified Port is a member of the PortCollection.

[Visual Basic]
Public Function Contains( _
   ByVal port As Port _
) As Boolean
[C#]
public bool Contains(
 Port port
);
[C++]
public: bool Contains(
 Port* port
);
[JScript]
public function Contains(
   port : Port
) : Boolean;

Parameters

port
The Port for which to check collection membership.

Return Value

true if the specified Port is a member of the PortCollection; otherwise, false.

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 Language Filter 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: