开发者

Using Linq Lambda Nested Expression to join two lists

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();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜