c# - How to split elements of the group in many lists? -
i have a list (originallist) elements of type mytype. type is:
mytype { long idreferenceelement; long idelement; string value; }
so separate in lists each group of elements, each group has elements same idreferenceelement.
for example, list of lists, each list of main list has elements of same group.
list<list<mytype>>
an example, have original list elements:
- item1(1,1,1);
- item2(1,2,2);
- item3(1,3,3);
- item4(2,4,4);
- item5(2,5,5);
- item6(2,6,6);
- item7(3,7,7);
- item8(3,8,8);
- item9(3,9,9);
i 3 lists:
list1 items: - item1(1,1,1); - item2(1,2,2); - item3(1,3,3);
list2: - item4(2,4,4); - item5(2,5,5); - item6(2,6,6);
list3: - item7(3,7,7); - item8(3,8,8); - item9(3,9,9);
to it, trying that:
list<list>> myresultlist = myoriginallist.groupby(x=>x.idreferenceelement).tolist();
it not work, because group element not list. know how access each group of grouping , covert list.
thanks much.
list<list<mytype>> myresultlist = myoriginallist.groupby(x=>x.idreferenceelement) .select(gr=>gr.tolist()) // convert each group list .tolist();
Comments
Post a Comment