{TOC}
| Namespace: | System.Linq |
| Assembly: | System.Core.dll |
| Extends: | IEnumerable<T> |
Back to
Standard Query Operator IndexEditIntroduction
The Intersect operator produces the set intersection of two sequences.
EditMethod Signatures
// 1 - Find the intersection between two sequences.
public static IEnumerable<TSource> Intersect<TSource>(
this IEnumerable<TSource> first,
IEnumerable<TSource> second)
// New in January CTP
// 2 - Find the intersection between two sequences using custom comparer
public static IEnumerable<TSource> Intersect<TSource>(
this IEnumerable<TSource> first,
IEnumerable<TSource> second,
IEqualityComparer<TSource> comparer)EditExceptions
Throws an ArgumentNullException if
first or
second are null.
EditPseudo-code
Overload 1
If
first is null, throw an ArgumentNullException.
If
second is null, throw an ArgumentNullException.
Iterate the
second sequence.
Add the current element to a list (list1).
Iterate the
first sequence.
If this element is in the list (list1) as determined using the EqualityComparer<TSource>.Default; comparer function.
Return the current element. (pick up from here when the next element is requested).
Overload 2 - custom comparer
If
first is null, throw an ArgumentNullException.
If
second is null, throw an ArgumentNullException.
If
comparer is null, default to
EqualityComparer<TSource>.Default;
Iterate the
second sequence.
Add the current element to a list (list1).
Iterate the
first sequence.
If this element is in the list (list1) as determined using the specified comparer function.
Return the current element. (pick up from here when the next element is requested).
EditLoop Count
1 loop through
second sequence initially, then 1 loop through the
first sequence as an iterator. This operator implements the standard
deferred execution iterator pattern. This means, no looping will occur until the result is iterated over.
EditCode Samples
TODO: Needs code sample.