connectseekers.com

Thursday, 5 May 2016

C# Dictionary Get Value By Key

5/05/2016 - By Pranav Singh 0


This article will show you how you can prepare a dictionary and perform search operation for value by using key name in c#.net.

So for this article we will create a new console application and add the below code.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        //c# dictionary get value by key
        static void Main(string[] args)
        {
            Console.WriteLine("Search For: Pakistan\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);

            if (dictionary.ContainsKey("Pakistan"))
            {
                int value = dictionary["Pakistan"];
                Console.WriteLine("Pakistan value is : " + value);
            }
            Console.WriteLine("\n\n------End Search--------\n");
            Console.ReadLine();
        }
    }
}

In above code I have prepared the dictionary and then added some value. After that I have search the value by key name. Hear I have shown example for Pakistan.


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