I have the following code:
List<MyClass> list1 = GetList1Contents();
List<MyClass> list2 = GetList2Contents();
foreach (MyClass eachClass in list1)
{
List<MyClass> results = (list2.Select(x => x.History.Selec开发者_如何学运维t(z => (z.Key == eachClass.ID))));
}
MyClass contains a List called History. What I’m trying to do is match any entries in list2 that have history entries in list 1 – but the compiler doesn’t like my syntax.
List<MyClass> results = list2.Where(x => x.History.Any(z => (z.Key == eachClass.ID))).ToList();
精彩评论