Wednesday, July 22, 2015

Dictionary- with a simple program

 It’s used to create a collection with pair of “Key” & “Value

Ex:
  • Key             Values
  • Maths         70
  • Phy             80
  • Chm            65


Path: System.Collections.Generic.Dictionary;


Program:
using System;
using System.Collections.Generic;

namespace Dictionary
{
    class Program
    {

        static void Main(string[] args)
        {
            Dictionary<string, int> Marks = new Dictionary<string, int>();
          
            Marks.Add("Maths",70);
            Marks.Add("Phy",79);
            Marks.Add("Chem",90);

            int m = Marks["Chem"];
            Console.WriteLine(m);   //OUTPUT: 90

            Console.ReadKey();
        }
    }
}

No comments:

Post a Comment