Lambda magic for that is:
List<Bridge> bridges = GetStuff();
Dictionary<int, List<int>> cleanResults = bridges.GroupBy(foo =>
foo.FooId).ToDictionary(bar => bar.Key, bar => bar.Select(x => x.BarId).ToList());
Without the .ToDictionary you would just have...
List<Bridge> bridges = GetStuff();
IEnumerable<IGrouping<int,int>> cleanResults = bridges.GroupBy(foo =>
foo.FooId);
No comments:
Post a Comment