user6350942 user6350942 - 1 month ago 5x
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?


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

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