简体   繁体   中英

C#: sort dictionary in descending order

How do I sort a keyvalue pair with descending order of their values?

foreach (KeyValuePair<string, int> item in keyvalue.OrderBy(key => key.Value))
            {
            } 

Use OrderByDescending instead of OrderBy .

foreach (var item in keyvalue.OrderByDescending(key => key.Value))
{

} 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM