Thank you again for your emails.I`ve been busy lately doing some code for my open source software i will be publishing next month.Again thank you for sending emails.I received 52 yesterday.
Today i will explain to you how to use these 2 classes Dictionary/SortedDictionary.
Dictonary
Step1:we have to import System.Collections.Generic:
using System.Collections.Generic;
Step2: we have to declare Dictionary object with new keyword
Dictionary
You have to remember that we are dealing with key/pair schema.
Step3:Now let`s add some items with Add(key,value) method
dic.Add(2000, "Talley");
dic.Add(10, "John");
dic.Add(200, "Sam");
Step4:Let`s use ContainsKey method to find values
if (dic.ContainsKey(2000))
{
string st = dic[10];
Console.WriteLine(st);
}
else
{
Console.WriteLine("No Match!");
}
You can also use ContainsValue method to query the Dictionay object.There are methods and
properties of Dictionay object you may have to take a look.
SortedDictionay and Dictonary classes have almost the same methods and properties except
SortedDictionay accepts IComparer
SortedDictionary<string,int> sd=new SortedDictionary<string,int>(IComparer<string>();
SortedDictionary
In a SortedDictionary elements must be sorted when they are added, making insertion times slower.
Remember you could also link table columns to these Dictionay objects.
Thank you for stopping by.See you next time.
If you have any question concerning this post please feel free to send me email at
johnstalley@live.com
Talley
Software Developer,ISV
Raleigh,NC
No comments:
Post a Comment