C# Expand Flat List<T> to Dictionary<T,ICollection<int>>
c#, dictionary, linq
Solution
var list = new List<MyClass>();
var dictionary = list.GroupBy(x => x.One)
.ToDictionary(x => x.Key, x => x.ToArray());
Problem
I've got a `List<MyClass>`: ``` public int MyClass { public int One { get; set; } public int Two { get; set; } } ``` Now, the data can (and does) look like this: One: 1, Two: 9 One: 2, Two: 9 One: 1, Two: 8 One: 3, Two: 7 See how "One" appears twice? I want to project this flat sequence into a grouped `Dictionary<int,ICollection<int>>`: KeyValuePairOne: { Key: 1, Value: { 9, 8 }} KeyValuePairTwo: { Key: 2, Value: { 9 }} KeyValuePairThree: { Key: 3, Value: { 7 }} I'm guessing i need to do a combination of `.GroupBy` and `.ToDictionary`?