connectseekers.com

Tuesday, 10 May 2016

C# Dictionary Search Key By Value

5/10/2016 - By Pranav Singh 0

This article will show you how you perform c# dictionary search key by value. In this we will pass the string value and get the key integer value.


So for this article we will create a new console application and add the below code.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Search For: America value\n");

            Dictionary<string, int> dictionary = new Dictionary<string, int>();
            dictionary.Add("India", 1);
            dictionary.Add("Pakistan", 2);
            dictionary.Add("Sri Lanka", 3);
            dictionary.Add("America", 4);

            var Value = (from data in dictionary
                         where data.Key == "America"
                         select data.Value).FirstOrDefault();
            if (dictionary.ContainsKey("Pakistan"))
            {
                //int value = dictionary["Pakistan"];
                Console.WriteLine("Pakistan key is : " + Value);
            }
            Console.WriteLine("\n\n------End Search--------\n");
            Console.ReadLine();
        }
    }
}

In above code I have search the value of America with in the Dictionary. Now we have done. Run the application to check the output.

About the Author

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Get Updates

Subscribe to our e-mail newsletter to receive updates.

Share This Post

0 comments:

Please let me know your view

Free Ebooks


About Us

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Contact Us

For writing article in this website please send request by your

GMAIL ID: dotnetpools@gmail.com
Email Id : contact@aspdotnet-pools.com

Bugs and Suggestions

As we all know that this website is for sharing knowledge and providing proper solution. So while reading the article is you find any bug or if you have any suggestion please mail us at contact@aspdotnet-pools.com.

Partners


Top jQuery Plugins

Global Classified : Connectseekers.com
© 2014
back to top