Introduction:
Dictionary is a generic type which means we can
use it with any data type .Dictionary take two parameter, Key and Value e.g: Dictionary<Tkey,TValue>. Dictionary is defined in the System.Collections.Generic namespace.
using System.Collections.Generic;
Syntax:
Dictionary<string,
string> <NameOfDictionary> = new Dictionary<string,
string>();
Code:
private static void Main(string[] args){
Dictionary<string, int> dictionary = new Dictionary<string, int>();
dictionary.Add("A", 1); //Add Data in Dictionary
dictionary.Add("B", 2);
dictionary.Add("C", 3);
dictionary.Add("D", 4);
dictionary.Add("E", 5);
foreach (var VARIABLE in dictionary)
{
Console.Write(VARIABLE.Key.ToString());
Console.Write(VARIABLE.Value.ToString());
Console.ReadLine();
}
}
Comments
Post a Comment