Working with List collection ToDictionary method

Rajesh_Kumar
Posted by Rajesh_Kumar under LINQ category on | Points: 40 | Views : 1837
ToDictionary is a mthod available in List collection which converts any List collection into a Dictionary collection.

For Example:
List<string> lst_names = new List<string>()
{
"Rajesh",
"Bhuvan",
"Prakash",
"Reema"
};

var names = lst_names.ToDictionary(g => g, g => true);

if (names.ContainsKey("Rajesh"))
{
Response.Write("Rajesh is present in a list collection");
}


Output: Rajesh is present in a list collection

Comments or Responses

Login to post response