Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
CopyTo Method

SortedList.CopyTo Method

Copies SortedList elements to a one-dimensional Array object, starting at the specified index in the array.

Namespace:  System.Collections
Assembly:  mscorlib (in mscorlib.dll)

abstract CopyTo : 
        array:Array * 
        arrayIndex:int -> unit  
override CopyTo : 
        array:Array * 
        arrayIndex:int -> unit

Parameters

array
Type: System.Array

The one-dimensional Array object that is the destination of the DictionaryEntry objects copied from SortedList. The Array must have zero-based indexing.

arrayIndex
Type: System.Int32

The zero-based index in array at which copying begins.

Implements

ICollection.CopyTo(Array, Int32)

ExceptionCondition
ArgumentNullException

array is a null reference (Nothing in Visual Basic).

ArgumentOutOfRangeException

arrayIndex is less than zero.

ArgumentException

array is multidimensional.

-or-

The number of elements in the source SortedList object is greater than the available space from arrayIndex to the end of the destination array.

InvalidCastException

The type of the source SortedList cannot be cast automatically to the type of the destination array.

The key/value pairs are copied to the Array object in the same order in which the enumerator iterates through the SortedList object.

To copy only the keys in the SortedList, use SortedList.Keys.CopyTo.

To copy only the values in the SortedList, use SortedList.Values.CopyTo.

This method is an O(n) operation, where n is Count.

The following code example shows how to copy the values in a SortedList object into a one-dimensional Array object.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

XNA Framework

Supported in: 3.0, 2.0, 1.0
Show:
© 2015 Microsoft