OrderedDictionary.CopyTo(Array, Int32) method is used to copy the OrderedDictionary elements to a one-dimensional Array object at the specified index.
public void CopyTo (Array array, int index);
array: It is the one-dimensional Array which is the destination of the DictionaryEntry objects copied from OrderedDictionary. The Array must have zero-based indexing.
index: it is the zero-based index in array at which copying begins.
Note: OrderedDictionary.CopyTo(Array, Int32) method doesn’t provide any guarantee to maintain the order of the elements in the OrderedDictionary collection.
Below programs illustrate the use of the above-discussed method:
key3-->value3 key4-->value4 key5-->value5 key2-->value2 key1-->value1
System.ArgumentOutOfRangeException: Non-negative number required.
Parameter name: arrayIndex
- C# | Copy ListDictionary to Array instance at the specified index
- C# | Get a read-only copy of the OrderedDictionary
- C# | Copy StringDictionary to Array at the specified index
- C# | Copy StringCollection at the specified index of array
- C# | Copying the Hashtable elements to an Array Instance
- C# | Insert into OrderedDictionary with key and value at specified index
- C# | Remove the entry at specified index from OrderedDictionary
- C# | Copy the elements of a string array to the end of the StringCollection
- C# | Remove all elements from OrderedDictionary
- C# | Copy the elements of collection over a range of elements in ArrayList
- C# | Copying the HybridDictionary entries to an Array Instance
- C# | Copy the Stack to an Array
- C# | Copy the entire LinkedList<T> to Array
- C# | How to copy the entire ArrayList to a one-dimensional Array
- Shallow Copy and Deep Copy in C#
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.