在列表中使用groupby方法 [英] Use of groupby method in list

查看:638
本文介绍了在列表中使用groupby方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在列表中应用groupby()

示例

假设i var a list =>



List< class> Lst =新列表();

列表< class> Lst1 =新列表();

和我加载数据

Lst =(

//这里的代码



).tolist();



现在



lst1 = lst.groupby(x => x.name).tolist();



i想要在lst1中加载项目但是它给出了erro

i want to apply groupby() on list
example
Suppose i var a list =>

List<class> Lst= new list();
List<class> Lst1= new list();
and i load data
Lst= (
// code here

).tolist();

and now

lst1= lst.groupby(x => x.name).tolist();

i want to load item in lst1 but it gives erro

推荐答案

当您对某些内容进行分组时,您可能会根据某些条件获取分组的组(在您的情况下,它是名称)。现在每个都可能有一个或多个元素。你可以计算每个组的聚合函数,如MAX,COUNT,AVERAGE等。



这里你没有对组进行任何可能的操作。问题出在第二部分,即



When you are grouping something, you are suppose to get groups which are divided based on some criteria (in your case, it is name). Now in each there could be one or more elements. You may calculate come aggregate function on each group such as MAX, COUNT, AVERAGE etc.

Here you did not do any of the possible operation on groups. Problem is on the second part, i.e.

lst1= lst.groupby(x => x.name).tolist();





您可以查看以下组子句的典型用法链接。



http:// code.msdn.microsoft.com/LINQ-to consumersSets-Grouping-c62703ea [ ^ ]


这篇关于在列表中使用groupby方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆