How can i select the value from the List of keyvaluepair based on checking the key value
List> myList = new
NOTE
The generic Dictionary class, introduced in .NET 2.0, uses KeyValuePair.
ITs better you make use of
Dictionary.ICollection>
and use ContainsKey Method
to check the the key is there or not ..
Example :
ICollection> openWith =
new Dictionary();
openWith.Add(new KeyValuePair("txt", "notepad.exe"));
openWith.Add(new KeyValuePair("bmp", "paint.exe"));
openWith.Add(new KeyValuePair("dib", "paint.exe"));
openWith.Add(new KeyValuePair("rtf", "wordpad.exe"));
if (!openWith.ContainsKey("txt"))
{
Console.WriteLine("Contains Given key");
}
EDIT
To get value
string value = "";
if (openWith.TryGetValue("tif", out value))
{
Console.WriteLine("For key = \"tif\", value = {0}.", value);
//in you case
//var list= dict.Values.ToList();
}
in your caseu it will be
var list= dict.Values.ToList();