0

I have a list which I want split up into x numbers of lists during runtime. Imagine a list "original" as such: (note that I do not know the number of values inside the list or what the values are before runtime)

1199.17
1199.17
1161.67
1161.67
1161.67
1161.67
1161.67
1199.17
1349.17
1349.17
1349.17
1311.67
1311.67
1311.67

I want to split this list into different list of the same numbers So list1 would be:

1199.17
1199.17

list2:

1161.67
1161.67
1161.67
1161.67
1161.67

etc.....

As you can imagine, because I do not know what the size or values inside "original" list is I do not know how many lists need to be created during runtime. How do I go about doing this in C#?

Breakwin
  • 84
  • 6
  • 5
    Try the linq groupby function: https://csharp.net-tutorials.com/linq/grouping-data-the-groupby-method/ – Connor Stoop Mar 30 '21 at 09:09
  • As stated above, use `GroupBy()`, but to be clear you'll need to convert groups to lists: `var lists = numbers.GroupBy(x => x).Select(group => group.ToList()).ToList();` This will give you a list of lists of double (for your case). – Matthew Watson Mar 30 '21 at 09:16

0 Answers0