C# | Get an ICollection containing keys in OrderedDictionary Last Updated : 11 Jul, 2025 Comments Improve Suggest changes Like Article Like Report OrderedDictionary.Keys property is used to get an ICollection object containing the keys in the OrderedDictionary collection. Syntax: public System.Collections.ICollection Keys { get; } Return Value: It returns an ICollection object containing the keys in the OrderedDictionary collection. Below given are some examples to understand the implementation in a better way: Example 1: CSHARP // C# code to get an ICollection // containing the keys in OrderedDictionary using System; using System.Collections; using System.Collections.Specialized; class GFG { // Driver method public static void Main() { // Creating a orderedDictionary named myDict OrderedDictionary myDict = new OrderedDictionary(); // Adding key and value in myDict myDict.Add("key1", "value1"); myDict.Add("key2", "value2"); myDict.Add("key3", "value3"); myDict.Add("key4", "value4"); myDict.Add("key5", "value5"); // Getting an ICollection containing // the keys in OrderedDictionary ICollection keyCollection = myDict.Keys; // Creating a String array String[] myKeys = new String[myDict.Count]; // Copying the OrderedDictionary elements to // a one-dimensional Array object at the // specified index. keyCollection.CopyTo(myKeys, 0); for (int i = 0; i < myDict.Count; i++) { Console.WriteLine(myKeys[i]); } } } Output: key1 key2 key3 key4 key5 Example 2: CSHARP // C# code to get an ICollection // containing the keys in OrderedDictionary using System; using System.Collections; using System.Collections.Specialized; class GFG { // Driver method public static void Main() { // Creating a orderedDictionary named myDict OrderedDictionary myDict = new OrderedDictionary(); // Adding key and value in myDict myDict.Add("A", "Apple"); myDict.Add("B", "Banana"); myDict.Add("C", "Cat"); myDict.Add("D", "Dog"); // Getting an ICollection containing // the keys in OrderedDictionary ICollection keyCollection = myDict.Keys; // Creating a String array String[] myKeys = new String[myDict.Count]; // Copying the OrderedDictionary elements to // a one-dimensional Array object at the // specified index. keyCollection.CopyTo(myKeys, 0); for (int i = 0; i < myDict.Count; i++) { Console.WriteLine(myKeys[i]); } } } Output: A B C D Reference: https://learn.microsoft.com/en-us/dotnet/api/system.collections.specialized.ordereddictionary.keys?view=netframework-4.7.2 Comment More infoAdvertise with us Next Article C# | Get an ICollection containing values in OrderedDictionary S Sahil_Bansall Follow Improve Article Tags : C# CSharp-Specialized-Namespace CSharp-Specialized-OrderedDictionary Similar Reads C# | Get an ICollection containing values in OrderedDictionary OrderedDictionary.Values property is used to get an ICollection object containing the values in the OrderedDictionary collection. Syntax: public System.Collections.ICollection Values { get; } Return Value: It returns an ICollection object containing the values in the OrderedDictionary collection. Be 2 min read C# | Get an ICollection containing the keys in ListDictionary ListDictionary.Keys property is used to get an ICollection containing the keys in the ListDictionary. Syntax: public System.Collections.ICollection Keys { get; } Return Value : It returns an ICollection containing the keys in the ListDictionary. Below are the programs to illustrate the use of ListDi 2 min read C# | Get an ICollection containing the values in ListDictionary ListDictionary.Values property is used to get an ICollection containing the values in the ListDictionary. Syntax: public System.Collections.ICollection Values { get; } Return Value : It returns an ICollection containing the values in the ListDictionary. Below are the programs to illustrate the use o 2 min read C# | Add key and value into OrderedDictionary collection OrderedDictionary.Add(Object, Object) method is used to add an entry with the specified key and value into the OrderedDictionary collection with the lowest available index. Syntax: public void Add (object key, object value); Parameters: key : The key of the entry to add. value : The value of the ent 2 min read C# | Gets an ICollection containing the keys in the Hashtable Hashtable.Keys Property is used to get an ICollection containing the keys in the Hashtable. Syntax: public virtual System.Collections.ICollection Keys { get; } Return Value: This property returns an ICollection containing the keys in the Hashtable. Note: The order of keys in the ICollection is unspe 2 min read C# | Get an ICollection containing the keys in HybridDictionary HybridDictionary.Keys property is used to get an ICollection containing the keys in the HybridDictionary. Syntax: public System.Collections.ICollection Keys { get; } Return Value: It returns an ICollection containing the keys in the HybridDictionary. Below programs illustrate the use of HybridDictio 2 min read Like