C# | Gets an ICollection containing the keys in the Hashtable Last Updated : 01 Feb, 2019 Comments Improve Suggest changes Like Article Like Report 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 unspecified. Retrieving the value of this property is an O(1) operation. Below programs illustrate the use of above-discussed property: Example 1: CSharp // C# code to get an ICollection containing // the keys in the Hashtable. using System; using System.Collections; class GFG { // Driver code public static void Main() { // Creating a Hashtable Hashtable myTable = new Hashtable(); // Adding elements in Hashtable myTable.Add("4", "Even"); myTable.Add("9", "Odd"); myTable.Add("5", "Odd and Prime"); myTable.Add("2", "Even and Prime"); // Get a collection of the keys. ICollection c = myTable.Keys; // Displaying the contents foreach(string str in c) Console.WriteLine(str + ": " + myTable[str]); } } Output: 5: Odd and Prime 9: Odd 2: Even and Prime 4: Even Example 2: CSharp // C# code to get an ICollection containing // the keys in the Hashtable. using System; using System.Collections; class GFG { // Driver code public static void Main() { // Creating a Hashtable Hashtable myTable = new Hashtable(); // Adding elements in Hashtable myTable.Add("India", "Country"); myTable.Add("Chandigarh", "City"); myTable.Add("Mars", "Planet"); myTable.Add("China", "Country"); // Get a collection of the keys. ICollection c = myTable.Keys; // Displaying the contents foreach(string str in c) Console.WriteLine(str + ": " + myTable[str]); } } Output: Chandigarh: City India: Country China: Country Mars: Planet Reference: https://docs.microsoft.com/en-us/dotnet/api/system.collections.hashtable.keys?view=netframework-4.7.2 Comment More infoAdvertise with us Next Article C# | Gets an ICollection containing the keys in the Hashtable K Kirti_Mangal Follow Improve Article Tags : C# CSharp-Collections-Hashtable CSharp-Collections-Namespace Similar Reads C# | Gets an ICollection containing the values in the Hashtable Hashtable.Values Property is used to get an ICollection containing the values in the Hashtable. Syntax: public virtual System.Collections.ICollection Values { get; } Return Value: This property returns an ICollection containing the values in the Hashtable. Note: The order of values in the ICollectio 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 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 keys in OrderedDictionary 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 give 2 min read C# | Get an ICollection containing the values in HybridDictionary HybridDictionary.Values property is used to get an ICollection containing the values in the HybridDictionary. Syntax: public System.Collections.ICollection Values { get; } Return Value: It returns an ICollection containing the values in the HybridDictionary. Below programs illustrate the use of Hybr 2 min read Like