Click here to Skip to main content
15,878,543 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Please help me out.
I have a list with multiple columns.
my requirement is to get a list with all the columns group by single column.

class SearchList
   string ComposerName;
   string MemberID;
   string Value1;
   String IteamName;
List<searchlist> sl=new List<searchlist>

above "sl" contains multiple items, from that i want to get MemberID, ComposerName, IteamName group by ComposerName using linq.

pleas suggest me code for this
Updated 13-Nov-12 19:42pm

1 solution

I assume that you have a list of your Class type like

List<SearchList> searchList = new List<SearchList>();

And for getting the desired result set by grouping the data try the below code

var groupedList = from entry in searchList
                  group entry by new { entry.ComposerName } into grouping
                  select new
                      ComposerName = grouping.Key.ComposerName,
                      MemberID = grouping.First().MemberID,
                      Value1 = grouping.First().Value1,
                      IteamName = grouping.First().IteamName,

Hope this helps. Please get back if you have any issue.
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