This tutorial shows you how to use Dictionary data type in c# code.

As you know, Dictionary type is a collection of Keys and Values, where key is like word and value is like definition. The Dictionary<TKey, TValue> class is a generic collection class in the System.Collection.Generics namespace.

You can declare a dictionary data type in c# as shown below.

var data = new Dictionary<string, string>();

You can add key value pairs to your Dictionary by using the Add method.


You can read data from the Dictionary object as shown below.

var value = data.Item("key1");