user6350942 user6350942 - 11 months ago 60
C# Question

Get Multiple List From An Ordered List in LINQ

i have this list in C#:

enter image description here

and i wanna divide it to 4 list like this :

enter image description here

how can i do this with Linq?

Answer Source

You want to group by Field1, so use Enumerable.GroupBy:

var field1GroupLists = mainList
    .GroupBy(x => x.Field1)
    .Select(group => group.ToList())