Click here to Skip to main content
15,886,258 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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
Posted
Comments
Richard C Bishop 15-May-13 15:38pm    
What error might that be?
maheshbisht 15-May-13 15:49pm    
at groupby line(At last) it gives conversion error into a list
Richard C Bishop 15-May-13 15:54pm    
What is the error?

1 solution

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.

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


You may check the typical usage of group clause in the following link.

http://code.msdn.microsoft.com/LINQ-to-DataSets-Grouping-c62703ea[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900