Set Theoretical and Sequencing Operators

So far, we’ve just been talking about sequences as the sources of data which LINQ operates on. Even though the use of sequences implies an ordering of elements, it doesn’t preclude certain set theoretical operations, such as intersection and union, to be defined. Besides those, some operations that have an inherent affinity to sequences exist.

Intersect

The intersection of two sequences consists of all the elements that exist in both of the sequences, where an existence check is based on an equality check:

static IEnumerable<T> Intersect<T>(this IEnumerable<T> first,                                   IEnumerable<T> second);static IEnumerable<T> Intersect<T>(this IEnumerable<T> ...

Get C# 5.0 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.