1: Cycle through the calendar, divided into ergodic key-value key value pairs and traverse all key two forms
2: Using LINQ Query method
1 Private voidGetdictkeybyvalue ()2 {3dictionary<int,string> dict =Newdictionary<int,string>();4Dict. ADD (1,"1");5Dict. ADD (2,"2");6Dict. ADD (3,"2");7Dict. ADD (4,"4");8 9 //foreach KeyValuePairTenlist<int> list =Newlist<int>(); One foreach(keyvaluepair<int,string> kvpinchdict) A { - if(KVP. Value.equals ("2")) - { theList. ADD (KVP. Key);//kvp. Key; - } - } - + //foreach dic. Keys - list. Clear (); + foreach(intKeyinchDict. Keys) A { at if(Dict[key]. Equals ("2")) - { -List. ADD (key);//Key - } - } - in //Linq -list<int> keylist = Dict. Where (q = Q.value = ="2") to. Select (q = q.key). tolist<int> ();//Get all keys + -Keylist = ( fromQinchDict the whereQ.value = ="2" * SelectQ.key). tolist<int> ();//Get all keys $ Panax Notoginseng varFirstkey = Dict. FirstOrDefault (q = Q.value = ="2"). Key;//get first key -}
C # Dictionary known value gets the corresponding key