When I have 2 List<string>
objects, then I can use Intersect
and Except
on them directly to get an output IEnumerable<string>
. That's simple enough, but what if I want the intersection/disjuction on something more complex?
Example, trying to get a collection of ClassA
objects which is the result of the intersect on ClassA
object's AStr1
and ClassB
object's BStr
; :
public class ClassA {
public string AStr1 { get; set; }
public string AStr2 { get; set; }
public int AInt { get; set; }
}
public class ClassB {
public string BStr { get; set; }
public int BInt { get; set; }
}
public class Whatever {
public void xyz(List<ClassA> aObj, List<ClassB> bObj) {
// *** this line is horribly incorrect ***
IEnumberable<ClassA> result =
aObj.Intersect(bObj).Where(a, b => a.AStr1 == b.BStr);
}
}
How can I fix the noted line to achieve this intersection.