我需要按照数字外观对列表进行排序,并仅显示重复项目一次。例如,我有以下列表:"a", "b", "a", "a", "c", "d", "c"
。我希望它像这样排序:"a","c","b",d"
。我怎样才能做到这一点?
这就是我所做的:
var something = from c in db.Letters
group c by c.letter into p
orderby p.Count()
select new
{
p.letter
};
但不能使用表达式p.letter。
答案 0 :(得分:0)
var resunt = from c in db.Letters
group c by c.letter into p
orderby p.Count() descending
select p.Key;
当您使用GroupBy
时,您会得到一个IGroupping
对象,其中包含您已分组的Key
对象的属性以及该组中值的集合。在您的情况下,您想要返回Key
- c.letter