This documentation is archived and is not being maintained.

ServiceCollection.CopyTo Method

Copies the entire ServiceCollection to a one-dimensional array of type Service, starting at the specified zero-based index of the target array.

[Visual Basic]
Public Sub CopyTo( _
   ByVal array() As Service, _
   ByVal index As Integer _
)
[C#]
public void CopyTo(
 Service[] array,
 int index
);
[C++]
public: void CopyTo(
 Service* array[],
 int index
);
[JScript]
public function CopyTo(
   array : Service[],
 index : int
);

Parameters

array
An array of type Service serving as the destination for the copy action.
index
The zero-based index at which to start placing the copied collection.

Example

[Visual Basic] 
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

[C#] 
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);
}

[C++] 
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);
}

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