1: The most straightforward method of looping can be divided into traversing key-value pairs and all keys.
2: query using the LINQ method (of course, the corresponding namespace using system. LINQ should be added here)
The following is a very simpleCodeExample:
Private Void Getdickeybyvalue () {dictionary < String , String > DIC = New Dictionary < String , String > (); DIC. Add ( " 1 " , " 1 " ); DIC. Add ( " 2 " , " 2 " ); DIC. Add ( " 3 " , " 2 " ); // Foreach keyvaluepair traversing Foreach (Keyvaluepair < String , String > KVp In DIC ){ If (KVp. value. Equals ( " 2 " )){ // ... KVp. Key; }} // Foreach DIC. Keys Foreach ( String Key In Dic. Keys ){ If (DIC [Key]. Equals ( " 2 " )){ // ... Key }} // LINQ VaR Keys = DIC. Where (q => q. value = " 2 " ). Select (q => q. Key ); // Get all keys List < String > Keylist = (From Q In Dic Where Q. value = " 2 " Select Q. Key). tolist < String > (); // Get all keys VaR Firstkey = DIC. firstordefault (q => q. value = " 2 " ). Key; // Get first key }
.....