📜  获取字典的键 - 无论代码示例

📅  最后修改于: 2022-03-11 14:57:37.284000             🧑  作者: Mango

代码示例1
using System;
using System.Collections.Generic;
using System.Linq;

namespace get_dictionary_key_by_value
{
    class Program
    {
        static void Main(string[] args)
        {
            Dictionary types = new Dictionary()
            {
                {"1", "one"},
                {"2", "two"},
                {"3", "three"}
            };
            string key = "";
            foreach(var pair in types)
            {
                if(pair.Value == "one")
                {
                    key = pair.Key;
                }
            }
            Console.WriteLine(key);
        }
    }
}