Dictionary Class
What is dictionary class in C# and how can i implement it?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Shivanand ArurPosted Sep 19, 2012, 7:48 AM
As I said, you can store data in key and value pair.... You have to define the type of value which you want to store in the Dictionary... This is a small example, which will help you to understand about Dictionary.
eg :
class MyClass
{
public static void Main()
{
Dictionary
myDictionary.Add("Value1",100);// Value1 is the Key and 100 is the value.
myDictionary.Add("Value2",200);
myDictionary.Add("Value3",300);
myDictionary.Add("Value4",400);
// Now, Will show you how to fetch a value from the Dictionary Object.
// Way 1
if(myDictionary.ContainsKey("Value1"))
{
int myFirstIntValue = myDictionary["Value1"];
Console.WriteLine(myFirstIntValue);
}
// Way 2 - Using For-Each Loop
foreach(KeyValuePair
{
}
}
}
Please mark this answer as Accepted if it helps you. Thanks :)
Check out this link for more help.