Introduction
Dictionary<> is an implemented class in the System.Collections.Generic namespace. A Dictionary is a lookup table that allows objects as keys and objects as values. A Dictionary is used when we have many different
elements. We must specify the types of its keys and values.
ADD Keys in Dictionary
The following example shows how to add the values in the dictionary and how to display the content of the dictionary.
Output
ContainsKey
Determine whether the key is present in the dictionary or not using the ContainsKey method. This method is used to find the key. The following code for finding the key in the dictionary is:
Output
![dictionary2.jpg]()
ContainsValue
Dictionary also helpfully implements a method called ContainsValue. This method is used to find the value.
It searches the entire collection. The following code is used to implement the ContainValue:
Output
![dictionary3.jpg]()
Remove
The following code is used to remove values from the dictionary:
Output
![dictionary4.jpg]()
Summary
In this article, I explained how to create a dictionary, add and remove elements from the dictionary and how to find the element from the dictionary using the ContainsKey and ContainsValue methods.
Read more: Dictionary In C#