compare two list and return not matching items using linq

后端 未结 10 566
死守一世寂寞
死守一世寂寞 2021-02-01 02:52

i have a two list

List SentList;
List MsgList;

both have the same property called MsgID;

MsgList            


        
10条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-01 03:06

    The naive approach:

    MsgList.Where(x => !SentList.Any(y => y.MsgID == x.MsgID))
    

    Be aware this will take up to m*n operations as it compares every MsgID in SentList to each in MsgList ("up to" because it will short-circuit when it does happen to match).

提交回复
热议问题