我有下面的代碼從一個字符串中提取關鍵字:添加OrderByDescending到LINQ聲明
var results = text.Split(new char[]{' ',',','.','!','?','_',':',';','/','(',')','\n','\r','-','*','"','/','\\','$','%','+','-','='}) // default split by whitespace
.GroupBy(str => str) // group words by the value
.Select(g => new
{
str = g.Key, // the value
count = g.Count() // the count of that value
});
現在我需要添加OrderByDescending
它,但不知道在哪裏把它。 .GroupBy(str => str).OrderByDescending(count => count)
產生了不正確的結果。如何使它正確?
+1以獲得更好的性能。請參閱[我的答案](http://stackoverflow.com/questions/4088064/add-orderbydescending-to-linq-statement/4088088#4088088)以獲得解釋。 – 2010-11-03 14:54:13