This documentation is archived and is not being maintained.

ServiceCollection.IndexOf Method

Searches for the specified Service and returns the zero-based index of the first occurrence within the ServiceCollection.

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

Parameters

service
The Service for which to search in the collection.

Return Value

A 32-bit signed integer.

Example

[Visual Basic] 
If myServiceDescription.Services.Contains(myService) Then
   Console.WriteLine( _
      "The mentioned service Exists at index {0} in the WSDL.", _
      myServiceDescription.Services.IndexOf(myService))
   Dim myServiceArray(myServiceDescription.Services.Count - 1) _
   As Service

   ' Copy the services into an array.
   myServiceDescription.Services.CopyTo(myServiceArray, 0)
   Dim myEnumerator As IEnumerator = myServiceArray.GetEnumerator()
   Console.WriteLine("The names of services in the array are")
   While myEnumerator.MoveNext()
      Dim myService1 As Service = CType(myEnumerator.Current, Service)
      Console.WriteLine(myService1.Name)
   End While
Else
   Console.WriteLine("Service does not exist in the WSDL.")
End If

[C#] 
if(myServiceDescription.Services.Contains(myService))
{
   Console.WriteLine(
      "The mentioned service exists at index {0} in the WSDL.",
      myServiceDescription.Services.IndexOf(myService));
   Service[] myServiceArray =
      new Service[myServiceDescription.Services.Count];

   // Copy the services into an array.
   myServiceDescription.Services.CopyTo(myServiceArray,0);
   IEnumerator myEnumerator = myServiceArray.GetEnumerator();
   Console.WriteLine("The names of services in the array are");
   while(myEnumerator.MoveNext())
   {
      Service myService1 = (Service)myEnumerator.Current;
      Console.WriteLine(myService1.Name);
   }
}
else
{
   Console.WriteLine("Service does not exist in the WSDL." );
}

[C++] 
if(myServiceDescription->Services->Contains(myService))
{
   Console::WriteLine(
      S"The mentioned service exists at index {0} in the WSDL.",
      __box(myServiceDescription->Services->IndexOf(myService)));
   Service* myServiceArray[] =
      new Service*[myServiceDescription->Services->Count];

   // Copy the services into an array.
   myServiceDescription->Services->CopyTo(myServiceArray,0);
   IEnumerator* myEnumerator = myServiceArray->GetEnumerator();
   Console::WriteLine(S"The names of services in the array are");
   while(myEnumerator->MoveNext())
   {
      Service* myService1 = dynamic_cast<Service*>(myEnumerator->Current);
      Console::WriteLine(myService1->Name);
   }
}
else
{
   Console::WriteLine(S"Service does not exist in the WSDL." );
}

[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

ServiceCollection Class | ServiceCollection Members | System.Web.Services.Description Namespace

Show: