Tablets.CopyTo Method

Tablets.CopyTo Method

Copies all of the elements of the current Tablets collection to the specified one-dimensional array, starting at the specified destination array index.

Definition

Visual Basic .NET Public Sub CopyTo( _
ByVal array As Array, _
ByVal index As Integer _
)
C# public void CopyTo(
Array array,
int index
);
Managed C++ public: void CopyTo(
Array *array,
int *index
);

Parameters

array System.Array. The one-dimensional array that is the destination of elements copied from the collection. The array must have zero-based indexing.
index System.Int32. The zero-based index in the array parameter at which copying begins.

Remarks

The elements are copied to the Array Leave Site object in the same order in which the enumerator iterates through the Tablets.

An exception is thrown if:

  • The array parameter is a null (Nothing in Microsoft® Visual Basic® .NET) reference.
  • The index parameter is less than zero.
  • The array parameter is multidimensional.
  • The index parameter is equal to or greater than the length of the array parameter.
  • The number of elements in the collection is higher than the available space from the index parameter to the end of the destination array parameter.

The type of the collection is cast automatically to the type of the destination array parameter. However, this method only copies elements to arrays of the same type as the elements of the collection or arrays of type Object Leave Site. Attempting to copy to another type of array causes an InvalidCastException Leave Site exceptionto be thrown.

This method is synchronized.

Examples

[C#]

This C# example fills part of an array of Tablet objects with the entire contents of the Tablets collection, starting at element 1 (the second element in a zero-based array) of the destination array theTablet and leaving the first element of the destination array (with an index of 0) empty. Note that just constructing a Tablets collection fills it with the available tablets.

Tablets theTablets = new Tablets();
Tablet[] theTablet = new Tablet[theTablets.Count + 1];
theTablets.CopyTo(theTablet, 1);
                

[VB.NET]

This Visual Basic .NET example fills part of an array of Tablet objects with the entire contents of the Tablets collection, starting at element 1 (the second element in a zero-based array) of the destination array theTablet and leaving the first element of the destination array (with an index of 0) empty. Note that just constructing a Tablets collection fills it with the available tablets.

Dim theTablets As New Tablets()
Dim theTablet(theTablets.Count) As Tablet
theTablets.CopyTo(theTablet, 1)