Answers for "Getting keys of dictionary"

0

Getting keys of dictionary

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

namespace get_dictionary_key_by_value
{
    class Program
    {
        static void Main(string[] args)
        {
            Dictionary<string, string> types = new Dictionary<string, string>()
            {
                {"1", "one"},
                {"2", "two"},
                {"3", "three"}
            };
            string key = "";
            foreach(var pair in types)
            {
                if(pair.Value == "one")
                {
                    key = pair.Key;
                }
            }
            Console.WriteLine(key);
        }
    }
}
Posted by: Guest on January-17-2022

Code answers related to "Getting keys of dictionary"

Browse Popular Code Answers by Language