1

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?

Rowland Shaw
  • 37,700
  • 14
  • 97
  • 166
AliBoronsi
  • 764
  • 1
  • 12
  • 19

1 Answers1

2

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

var field1GroupLists = mainList
    .GroupBy(x => x.Field1)
    .Select(group => group.ToList())
    .ToList();
Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939