Collection<T>.CopyTo(T[], Int32) Метод
Определение
Копирует целый массив Collection<T> в совместимый одномерный массив Array, начиная с заданного индекса целевого массива.Copies the entire Collection<T> to a compatible one-dimensional Array, starting at the specified index of the target array.
public:
virtual void CopyTo(cli::array <T> ^ array, int index);
public void CopyTo (T[] array, int index);
abstract member CopyTo : 'T[] * int -> unit
override this.CopyTo : 'T[] * int -> unit
Public Sub CopyTo (array As T(), index As Integer)
Параметры
- array
- T[]
Одномерный массив Array, в который копируются элементы из интерфейса Collection<T>.The one-dimensional Array that is the destination of the elements copied from Collection<T>. Массив Array должен иметь индексацию, начинающуюся с нуля.The Array must have zero-based indexing.
- index
- Int32
Отсчитываемый от нуля индекс в массиве array
, указывающий начало копирования.The zero-based index in array
at which copying begins.
Реализации
Исключения
array
имеет значение null
.array
is null
.
Значение параметра index
меньше нуля.index
is less than zero.
Число элементов в исходной коллекции Collection<T> больше доступного места от положения, заданного значением параметра index
, до конца массива назначения array
.The number of elements in the source Collection<T> is greater than the available space from index
to the end of the destination array
.
Комментарии
Этот метод использует Array.Copy для копирования элементов.This method uses Array.Copy to copy the elements.
Элементы копируются в в том Array же порядке, в котором перечислитель выполняет итерацию по Collection<T> .The elements are copied to the Array in the same order in which the enumerator iterates through the Collection<T>.
Этот метод является n
операцией O (), где n
имеет Count .This method is an O(n
) operation, where n
is Count.