How to use Dictionary class in Systems.Collections.Generic?
Yogesh Jadhav
Select an image from your device to upload
Create a Dictionary object and populate it and enumerate it to display key value pairs.
For example, to create a Dictionary object that has integer as key and string as value, we can create dictionary object in the following way:
Dictionary dictNames =new Dictionary();
dictNames.Add(1,”Raj”);
dictNames.Add(3,”Ravi”);
dictNames.Add(5,”Kevin”);
In order to retrieve above value enumerate it i.e use foreach loop and use KeyValuePair object as the elements are retrieved as KeyValuePair objects
foreach(KeyValuePair kvpName in dictNames)
Console.WriteLine(kvpName.Key+” “+kvpName.Value);