【发布时间】:2015-10-01 19:34:17
【问题描述】:
我想根据用户发布帖子的次数来排序一些帖子。
我有以下几点:
IList<User> orderTopContributors =
this.GetPosts()
.GroupBy(x => x.Author.Id)
.Select(x => new
{
AuthorCount = x.Count()
})
.OrderByDescending( x => x.AuthorCount )
.ToList();
我哪里出错了?转换有错误:
严重性代码描述项目文件行错误CS0266不能 将类型“System.Collections.Generic.List
>”隐式转换为 'System.Collections.Generic.IList'。显式转换 存在(您是否缺少演员表?)
【问题讨论】:
-
OrderByDescending -
感谢您的关注,呵呵。
-
当您应用
Select子句时,您会得到一个IEnumerable对象,其元素是Select中定义的新类型,因此,当您在Select子句中添加“新”时, Linq 返回一个IEnumerable新类型列表。