compare two list and return not matching items using linq

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

    You can do something like

    var notSent = MsgSent.Except(MsgList, MsgIdEqualityComparer);
    

    You will need to provide a custom equality comparer as outlined on MSDN

    http://msdn.microsoft.com/en-us/library/bb336390.aspx

    Simply have that equality comparer base equality only on MsgID property of each respective type. Since the equality comparer compares two instances of the same type, you would need to define an interface or common base type that both Sent and Messages implement that has a MsgID property.

提交回复
热议问题