2
で明確な独特の出現箇所を数えラムダ式。ソートは、私は、LINQで最も出現箇所の大きい順に、以下のリストをソートする方法を疑問に思ってLINQ
で明確な独特の出現箇所を数えラムダ式。ソートは、私は、LINQで最も出現箇所の大きい順に、以下のリストをソートする方法を疑問に思ってLINQ
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() ...
あなたは出現順明確なリストを取得したい場合は、することでグループを使用します。私は持っているが、私は、スローアウェイ変数のための二重文字の構文の大ファンだ
var query = foo.GroupBy(xx => xx)
.OrderByDescending(gg => gg.Count())
.Select(gg => gg.Key);
// on your input returns:
// abc
// def
// ghj
他の人々がそれらを嫌うので、その習慣を取り除こうとしている。私は一人ではないことを嬉しく思う – HugoRune