Linq Except considering only one property

后端 未结 1 1440
栀梦
栀梦 2021-01-07 21:37

I have two lists of object.

List obj1 = new List();

List obj2 = new List(); 

I

相关标签:
1条回答
  • 2021-01-07 22:22

    The Except method requires that the two collection types involved have the same element type. In this case the element types are different (object1 and object2) hence Except isn't really an option. A better method to use here is Where

    obj2 = obj2
      .Where(x => !obj1.Any(y => y.StringProperty == x.StringProperty))
      .ToList();
    
    0 讨论(0)
提交回复
热议问题