I have 2 lists with some data in:
List1.Add(new Filter { Name = "Foo", Value = "Bar" });
List2.Add(new Filter { Name = "Foo", Value = "Bar" });
I would like to use Linq to return true if List1 contains ALL the values in List2, the example above would obviously return true but this is an example but if I added
List2.Add(new Filter { Name = "Foo1", Value = "Bar1" });
then it should return false.
I started going down the lines of:
var Result = from item1 in List1
join item2 in List2 on item1.Name equals item2.Name
new { item1, item2 };
but this would only match on the Name and I’m pretty sure I am going down the wrong route with this.
EDIT: Just to clarify, I don’t want only the VALUE property. Name && Value must match in both lists.
You can use
Except:Edit According to your last edit that you want to compare all properties of
Filter, the best approach is to create a customIEqualityComparer<Filter>and use that as argument for thisEnumerable.Exceptoverload:Now this works: