top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to Get the Dictionary Key by value in C# ?

0 votes
376 views
How to Get the Dictionary Key by value in C# ?
posted May 7, 2016 by Latha

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote
 
Best answer
using System;
using System.Collections.Generic;
using System.Linq;

namespace ACCode
{
    class Program
    {
        static void Main(string[] args)
        {
            Dictionary<string, string> dictionaryItems= new Dictionary<string, string>()
            {
                {"1", "One"},
                {"2", "Two"},
                {"3", "Three"},
                {"4", "Three"},
                {"5", "Three"}
            };
            var dictValue = dictionaryItems.FirstOrDefault(x => x.Value == "Three").Key;
            Console.WriteLine(dictValue);
            Console.ReadLine();
        }       
    } 
}
answer May 7, 2016 by Shivaranjini
...