Copies the entire xtd::collections::generic::list <type_t> to a compatible one-dimensional array, starting at the specified index of the target array.
- Parameters
-
index | The zero-based index in the source xtd::collections::generic::list <type_t> at which copying begins. |
array | The one-dimensional sxtd::array that is the destination of the elements copied from ICollection. The sxtd::array must have zero-based indexing. |
arrayIndex | The zero-based index in array at which copying begins; |
count | The number of elements to copy. |
- Exceptions
-
ArgumentNullException | array is null. |
ArgumentOutOfRangeException | The arrayIndex or count is less than 0. |
ArgumentException | The number of elements in the source xtd::collections::generic::list <type_t> is greater than the number of elements that the destination array can contain. |
- Examples
- The following code example demonstrates all three overloads of the CopyTo method. A xtd::collections::generic::list <type_t> of strings is created and populated with 5 strings. An empty string array of 15 elements is created, and the CopyTo(T[]) method overload is used to copy all the elements of the list to the array beginning at the first element of the array. The CopyTo(T[], Int32) method overload is used to copy all the elements of the list to the array beginning at array index 6 (leaving index 5 empty). Finally, the CopyTo(Int32, T[], Int32, Int32) method overload is used to copy 3 elements from the list, beginning with index 2, to the array beginning at array index 12 (leaving index 11 empty). The contents of the array are then displayed.