ListDictionary.CopyTo(Array, Int32) method is used to copy the ListDictionary entries to a one-dimensional Array instance 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 ListDictionary. The Array must have zero-based indexing.
index : The zero-based index in array at which copying begins.
- ArgumentNullException : If the array is null.
- ArgumentOutOfRangeException : If the index is less than zero.
- InvalidCastException : If the type of the source ListDictionary cannot be cast automatically to the type of the destination array.
- ArgumentException : If the array is multidimensional OR the number of elements in the source ListDictionary is greater than the available space from index to the end of the destination array.
Below given are some examples to understand the implementation in a better way:
Australia-->Canberra Belgium-->Brussels Netherlands-->Amsterdam China-->Beijing Russia-->Moscow India-->New Delhi
System.ArgumentOutOfRangeException: Index is less than zero.
Parameter name: index
- The elements are copied to the Array in the same order in which the enumerator iterates through the ListDictionary.
- To copy only the keys in the ListDictionary, use ListDictionary.Keys.CopyTo.
- To copy only the values in the ListDictionary, use ListDictionary.Values.CopyTo.
- This method is an O(n) operation, where n is Count.
- C# | Copy OrderedDictionary elements to Array instance at the specified index
- C# | Remove the entry with specified key from ListDictionary
- C# | Add the specified key and value into the ListDictionary
- C# | Get or set the value associated with specified key in ListDictionary
- C# | Copy StringCollection at the specified index of array
- C# | Copy StringDictionary to Array at the specified index
- Creating an Index From the Specified Index at the Start of a Collection in C#
- Creating an Index From the End of a Collection at a Specified Index Position in C#
- C# | Check if two ListDictionary objects are equal
- C# | ListDictionary Class
- C# | Remove all entries from the ListDictionary
- C# | Get the number of key/value pairs contained in ListDictionary
- C# | Get an ICollection containing the values in ListDictionary
- C# | Get an ICollection containing the keys in ListDictionary
- C# | Check if ListDictionary is synchronized (thread safe)
- C# | Check if ListDictionary is read-only
- C# | Check if ListDictionary has a fixed size
- C# | Check if ListDictionary contains a specific key
- C# | Get an enumerator that iterates through the ListDictionary
- How to get Synchronize access to the ListDictionary 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.