1 private void GetDicKeyByValue() 2 { 3 Dictionarydic = new Dictionary (); 4 dic.Add("1", "1"); 5 dic.Add("2", "2"); 6 dic.Add("3", "2"); 7 //foreach KeyValuePair traversing 8 foreach (KeyValuePair kvp in dic) 9 {10 if (kvp.Value.Equals("2"))11 { 12 //...... kvp.Key;13 }14 }15 16 //foreach dic.Keys17 foreach (string key in dic.Keys)18 {19 if (dic[key].Equals("2"))20 { 21 //...... key22 }23 }24 25 //Linq26 var keys = dic.Where(q => q.Value == "2").Select(q => q.Key); //get all keys27 28 List keyList = (from q in dic29 where q.Value == "2"30 select q.Key).ToList (); //get all keys31 32 var firstKey = dic.FirstOrDefault(q => q.Value == "2").Key; //get first key33 }