正如您在查询中提到的降序一样,我假设您需要最近 10 次出现。如果是这样
var sortedDict = (from entry in dd orderby entry.Value descending select entry)
.Take(10)
.ToDictionary(pair => pair.Key, pair => pair.Value) ;
var sortedDict = dd.OrderByDescending(entry=>entry.Value)
.Take(10)
.ToDictionary(pair=>pair.Key,pair=>pair.Value);
如果您需要前 10 个,只需删除descending
它就可以正常工作。
var sortedDict = (from entry in dd orderby entry.Value select entry)
.Take(10)
.ToDictionary(pair => pair.Key, pair => pair.Value) ;
var sortedDict = dd.OrderBy(entry=>entry.Value)
.Take(10)
.ToDictionary(pair=>pair.Key,pair=>pair.Value);