Having two generic lists of type List<MyClass>, how do I remove from List1 all the instances of List2, matching a property?
This is the setup. I have a class:
public class MyClass
{
public int MyValue { get; set; }
public int MyOtherValue { get; set; }
}
And two lists:
List<MyClass> list1 = new List<MyClass>();
list1.Add(new MyClass() { MyValue = 1, MyOtherValue = 10 });
list1.Add(new MyClass() { MyValue = 2, MyOtherValue = 20 });
list1.Add(new MyClass() { MyValue = 3, MyOtherValue = 30 });
list1.Add(new MyClass() { MyValue = 4, MyOtherValue = 40 });
List<MyClass> list2 = new List<MyClass>();
list2.Add(new MyClass() { MyValue = 2, MyOtherValue = 50 });
list2.Add(new MyClass() { MyValue = 3, MyOtherValue = 60 });
I want to remove all list2 instances from list1 matching on MyValue property.