Copies the entire xtd::collections::generic::list <type_t> to a compatible one-dimensional array.
- Parameters
-
array | The one-dimensional xtd::array that is the destination of the elements copied from ICollection. The xtd::array must have zero-based indexing. |
- Exceptions
-
ArgumentNullException | array is null. |
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.