compare two list and return not matching items using linq

后端 未结 10 549
死守一世寂寞
死守一世寂寞 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:08

    You could do something like:

    HashSet sentIDs = new HashSet(SentList.Select(s => s.MsgID));
    
    var results = MsgList.Where(m => !sentIDs.Contains(m.MsgID));
    

    This will return all messages in MsgList which don't have a matching ID in SentList.

提交回复
热议问题