score:0

If you have a union and intersection of the form:

var union = source.Where(predicate0).Union(source.Where(predicate1));
var inter = source.Where(predicate0).Intersect(source.Where(predicate1));

Then union will have the values for which either predicate0 or predicate1 was true while inter will have the values for which both predicate0 and predicate1 were true.

For this reason, the following would have the same result:

var union = source.Where(predicate0.Or(predicate1));
var inter = source.Where(predicate0.And(predicate1));

This depends upon the components of the union and intersection being produced by two Where queries though. In the likes of:

var union = source1.Where(predicate0).Select(item => item.ID)
  .Union(source2.Where(predicate1).Select(item => item.ID));

Then it's likely that the predicates aren't even of the same type, and there are yet other cases where combining predicates will not work as a replacement of Union and Intersect.

It is though useful to be able to consider the first examples both ways, in terms of one's understanding of how predicates, unions and intersections work.


Related Articles