Last active
October 15, 2018 08:53
-
-
Save vgebrev/0e47919fd47e6ee8d9a3df8494c7a49f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DataClass | |
{ | |
public int Id { get; set; } | |
public int MyInt { get; set; } | |
} | |
var ids = new List<int> { 1, 3 }; | |
var data = new List<DataClass> { | |
new DataClass { Id = 1, MyInt = 10 }, | |
new DataClass { Id = 1, MyInt = 11 }, | |
new DataClass { Id = 2, MyInt = 12 }, | |
new DataClass { Id = 3, MyInt = 13 }, | |
}; | |
var dictionary = data.GroupBy(d => d.Id) | |
.Where(g => ids.Contains(g.Key)) | |
.ToDictionary( | |
k => k.Key, | |
v => v.Select(d => d.MyInt).ToList() | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment