Linq selecting items that exist in both list

后端 未结 2 589
北恋
北恋 2021-01-17 07:11

I have 2 list:

myObject object1 = new myObject(id = 1, title = \"object1\"};
myObject object2 = new myObject(id = 2, title = \"object2\"};
myObject object3 =         


        
相关标签:
2条回答
  • 2021-01-17 07:54

    LINQ Solution:

    myObjectList = myObjectList.Where(X => idList.Contains(X.id)).ToList();
    
    0 讨论(0)
  • 2021-01-17 08:07
    IEnumerable<myObject> matches = myObjectList.Join(
        idList,
        o => o.Id,
        id => id,
        (o, id) => o);
    
    0 讨论(0)
提交回复
热议问题