If you want the MyObject list to match, you can do:
var solution = objects.Where(x=> ids.Contains(x.id));
Instead, you get a List<T>
, where T
is an anonymous type with 2 properties, Id
, which is a string that acts as a “key” in this particular case, and Obj
, a list of MyObject
, which id matches the Id property.
var solution = ids.Select(x=>new{ Id = x, Obj=objects.Where(y=>y.id == x).ToList()}) .ToList();
source share