This documentation is archived and is not being maintained.

PortCollection.IndexOf Method

Searches for the specified Port and returns the zero-based index of the first occurrence within the collection.

[Visual Basic]
Public Function IndexOf( _
   ByVal port As Port _
) As Integer
[C#]
public int IndexOf(
 Port port
);
[C++]
public: int IndexOf(
 Port* port
);
[JScript]
public function IndexOf(
   port : Port
) : int;

Parameters

port
The Port for which to search in the collection.

Return Value

A 32-bit signed integer.

Example

[Visual Basic] 
myPortCollection = myService.Ports

' Create an array of Port objects.
Console.WriteLine(ControlChars.NewLine & "Port collection :")
Dim myPortArray(myService.Ports.Count) As Port
myPortCollection.CopyTo(myPortArray, 0)
Dim i1 As Integer
For i1 = 0 to myService.Ports.Count -1
   Console.WriteLine("Port[" & i1.ToString + "] : " & _
      myPortArray(i1).Name)
Next
Dim myIndexPort As Port = myPortCollection(0)
Console.WriteLine(ControlChars.NewLine + ControlChars.NewLine + _
                  "The index of port '" + myIndexPort.Name + "' is : " + _
                  myPortCollection.IndexOf(myIndexPort).ToString)

[C#] 
myPortCollection = myService.Ports;

// Create an array of Port objects.
Console.WriteLine("\nPort collection :");
Port[] myPortArray = new Port[myService.Ports.Count];
myPortCollection.CopyTo(myPortArray, 0);
for(int i1=0 ; i1 < myService.Ports.Count ; ++i1)
{
   Console.WriteLine("Port[" + i1+ "] : " + myPortArray[i1].Name);
}
Port myIndexPort = myPortCollection[0];
Console.WriteLine("\n\nThe index of port '"
   +  myIndexPort.Name + "' is : "
   +  myPortCollection.IndexOf(myIndexPort));

[C++] 
myPortCollection = myService->Ports;

// Create an array of Port objects.
Console::WriteLine(S"\nPort collection :");
Port* myPortArray[] = new Port*[myService->Ports->Count];
myPortCollection->CopyTo(myPortArray, 0);
for(int i1=0 ; i1 < myService->Ports->Count ; ++i1)
{
   Console::WriteLine(S"Port[{0}] : {1}", __box(i1), myPortArray[i1]->Name);
}
Port* myIndexPort = myPortCollection->Item[0];
Console::WriteLine(S"\n\nThe index of port '{0}' is : {1}",
   myIndexPort->Name, __box(myPortCollection->IndexOf(myIndexPort)));

[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: