Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I gave a List
Name  Dep  YearofJoin
====================
x     d     2010
y     d     2010

a     g     2010
b     g     2010
c     g     2012
====================


I want to group the elements based on Dep and then group then based on yearOf Joining

I am using groupby(dep) but am not able to move further.

Any suggestion.

[edit]Code block added - OriginalGriff[/edit]
Posted
Updated 16-May-13 21:57pm
v2
Comments
kumar2413 17-May-13 2:58am    
What would your output look then?gv some sample output then can help you well
rohit24c 17-May-13 3:17am    
Name Dep YearofJoin
====================
x d 2010
y d 2010

a g 2010
b g 2010
c g 2012
====================
from this i want (y d 2010) & ((b g 2010) & (c g 2012))

Mean to say after groupby(Dep) i will get 2 groups from that group i want 1 more group
kumar2413 17-May-13 3:27am    
The question not very clear bro

1 solution

According to your query, those names would come under one group which has same Dep and same YearofJoin. Therefore, from the given example, we would get 3 groups (2010_d), (2010_g) and (2012_g)

C#
var studentGroups = from s in students
	group s by string.Format("{0}_{1}", s.YearofJoin, s.Dep) into g
	select new { GroupId = g.Key, StudentInfo = g };


foreach (var sg in studentGroups)
{
	foreach (var s in sg.StudentInfo)
	{
	}
}
 
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