C# Dictionary example

This show how easy it is to add key and value pairs in the dictionary and use it.


using System;
using System.Collections.Generic;

class DictionaryExample
    public static void Main()
        Dictionary<string, int> dict = new Dictionary<string, int>();

        // Add elements to the collection.
        dict.Add("A", 52);
        dict.Add("B", 72);
        dict.Add("C", 110);
        dict.Add("D", 63);
        dict.Add("E", 100);

        foreach (string str in dict.Keys)
            Console.WriteLine("At key {0} , value is {1}", str, dict[str]);


At key A , value is 52
At key B , value is 72
At key C , value is 110
At key D , value is 63
At key E , value is 100

Leave a Reply




You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>