Practical Usage of Adding Items to Generic Dictionary<K,T>

In this blog we are going to see, How to add items to dictionary and displaying it the key Value format.

Used Namespaces:

using System;

using System.Collections.Generic;

using System.Linq;


Step 1:                 Adding items to Dictionary as KeyValuePair

 

            Dictionary<int, string> dic = new Dictionary<int, string>();

            dic.Add(1, "Lajapathy");

            dic.Add(2, "Parthiban");

            dic.Add(3, "AnandBabu");

            dic.Add(4, "Sathiya");

                          

Step 2:                 Displaying the Dictionary Items

 

            foreach (KeyValuePair<int, string> tempDic in dic)

            {

                Response.Write("Key :" + tempDic.Key + " value :" + tempDic.Value + "<br/>");

            }


Output :

Key :1 value :Lajapathy
Key :2 value :Parthiban
Key :3 value :AnandBabu
Key :4 value :Sathiya

Ebook Download
View all
Learn
View all