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 HybridDictionary.Keys Property:
Example 1:
// C# code to get an ICollection containing // the keys in the HybridDictionary. using System; using System.Collections; using System.Collections.Specialized; class GFG { // Driver code public static void Main() { // Creating a HybridDictionary named myDict HybridDictionary myDict = new HybridDictionary(); // Adding key/value pairs in myDict myDict.Add("A", "Apple"); myDict.Add("B", "Banana"); myDict.Add("C", "Cat"); myDict.Add("D", "Dog"); myDict.Add("E", "Elephant"); myDict.Add("F", "Fish"); // Creating a String arr named myArr String[] myArr = new String[myDict.Count]; // copying the Keys in HybridDictionary // to a one-dimensional Array instance // at the specified index. myDict.Keys.CopyTo(myArr, 0); // To get an ICollection containing // the keys in the HybridDictionary for (int i = 0; i < myDict.Count; i++) Console.WriteLine(myArr[i]); } } |
chevron_right
filter_none
Output:
A B C D E F
Example 2:
// C# code to get an ICollection containing // the keys in the HybridDictionary. using System; using System.Collections; using System.Collections.Specialized; class GFG { // Driver code public static void Main() { // Creating a HybridDictionary named myDict HybridDictionary myDict = new HybridDictionary(); // Adding key/value pairs in myDict myDict.Add("I", "first"); myDict.Add("II", "second"); myDict.Add("III", "third"); myDict.Add("IV", "fourth"); myDict.Add("V", "fifth"); // Creating a String arr named myArr String[] myArr = new String[myDict.Count]; // copying the Keys in HybridDictionary // to a one-dimensional Array instance // at the specified index. myDict.Keys.CopyTo(myArr, 0); // To get an ICollection containing // the keys in the HybridDictionary for (int i = 0; i < myDict.Count; i++) Console.WriteLine(myArr[i]); } } |
chevron_right
filter_none
Output:
I II III IV V
Note:
- The order of the values in the ICollection is unspecified, but it is the same order as the associated values in the ICollection returned by the Values method.
- The returned ICollection is not a static copy. Instead, the ICollection refers back to the keys in the original HybridDictionary. Therefore, changes to the HybridDictionary continue to be reflected in the ICollection.
- Retrieving the value of this property is an O(1) operation.
Reference:
Recommended Posts:
- C# | Get an ICollection containing the values in HybridDictionary
- C# | Get an ICollection containing the keys in ListDictionary
- C# | Get an ICollection containing keys in OrderedDictionary
- C# | Gets an ICollection containing the keys in the Hashtable
- C# | Get an ICollection containing the values in ListDictionary
- C# | Get an ICollection containing values in OrderedDictionary
- C# | Gets an ICollection containing the values in the Hashtable
- C# | Get an enumerator that iterates through the HybridDictionary
- How to get Synchronize access to the HybridDictionary in C#
- C# | Creating a HybridDictionary with specified initial size & case sensitivity
- C# | Creating an empty HybridDictionary with specified case sensitivity
- C# | Check the HybridDictionary for a specific key
- C# | HybridDictionary Class
- C# | Adding the specified key and value into HybridDictionary
- C# | Check if HybridDictionary is Synchronized (thread safe)
- C# | Check if HybridDictionary is read only
- C# | Check if HybridDictionary has fixed size
- C# | Count the number of key/value pairs in HybridDictionary
- C# | Removing all entries from HybridDictionary
- C# | Copying the HybridDictionary entries to an Array Instance
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.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.

