VOOZH about

URL: https://www.geeksforgeeks.org/c-sharp/c-sharp-check-if-sorteddictionary-contains-the-specified-key-or-not/

⇱ C# | Check if SortedDictionary contains the specified key or not - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

C# | Check if SortedDictionary contains the specified key or not

Last Updated : 11 Jul, 2025
SortedDictionary<TKey, TValue>.ContainsKey(TKey) Method is used to check whether the SortedDictionary contains an element with the specified key or not. Syntax:
public bool ContainsKey (TKey key);
Here, the key is the Key which is to be located in the SortedDictionary. Returns Value: This method will return true if the Dictionary contains an element with the specified key otherwise, it returns false. Exception: This method will give ArgumentNullException if the key is null. Below are the programs to illustrate the use of the above-discussed method: Example 1:
Output:
Key : 4 is present
Example 2:
Comment

Explore