2012-04-23 1 views

答えて

4
string[] names = { "ghj", "def", "abc", "def", "abc", "abc" }; 

IEnumerable<string> query = names 
    .GroupBy(s=>s) // groups identical strings into an IGrouping 
    .OrderByDescending(group => group.Count()) // IGrouping is a collection, so you can count it 
    .Select(group=>group.Key); // IGrouping has a Key, which is the thing you used to group with. In this case group.Key==group.First()==group.skip(1).First() ... 
2

あなたは出現順明確なリストを取得したい場合は、することでグループを使用します。私は持っているが、私は、スローアウェイ変数のための二重文字の構文の大ファンだ

var query = foo.GroupBy(xx => xx) 
       .OrderByDescending(gg => gg.Count()) 
       .Select(gg => gg.Key); 
// on your input returns: 
// abc 
// def 
// ghj 
+0

他の人々がそれらを嫌うので、その習慣を取り除こうとしている。私は一人ではないことを嬉しく思う – HugoRune

関連する問題