xtd 0.2.0
Loading...
Searching...
No Matches

◆ copy_to() [3/3]

template<typename type_t , typename allocator_t = xtd::collections::generic::helpers::allocator<typename std::conditional<std::is_same<bool, type_t>::value, char, type_t>::type>>
virtual void xtd::collections::generic::list< type_t, allocator_t >::copy_to ( size_type  index,
xtd::array< type_t > &  array,
size_type  array_index,
size_type  count 
) const
inlinevirtual

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
indexThe zero-based index in the source xtd::collections::generic::list <type_t> at which copying begins.
arrayThe one-dimensional xtd::array that is the destination of the elements copied from ICollection. The xtd::array must have zero-based indexing.
arrayIndexThe zero-based index in array at which copying begins;
countThe number of elements to copy.
Exceptions
ArgumentNullExceptionarray is null.
ArgumentOutOfRangeExceptionThe arrayIndex or count is less than 0.
ArgumentExceptionThe 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.
Remarks
TThis method uses xtd::array::copy to copy the elements.
The elements are copied to the xtd::array in the same order in which the enumerator iterates through the xtd::collections::generic::list <type_t>.
This method is an O(n) operation, where n is xtd::collections::generic::list::count.
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(type_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(type_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, type_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.