开发者

Using Linq Lambda Nested Expression to join two lists

开发者 https://www.devze.com 2023-01-29 19:30 出处:网络
I have the following code: List<MyClass> list1 = GetList1Contents(); List<MyClass> list2 = GetList2Contents();

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

精彩评论

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