{TOC}
| Namespace: | System.Linq |
| Assembly: | System.Core.dll |
| Extends: | IEnumerable<T> |
Back to
Standard Query Operator IndexEditIntroduction
The Union operator produces the set union of two sequences.
EditMethod Signatures
// 1 - Returns elements which appear in both sequences.
public static IEnumerable<TSource> Union<TSource>(IEnumerable<TSource> first, IEnumerable<TSource> second)
// New in January CTP
// 2 - Returns elements which appear in both sequences, using a custom comparer function
public static IEnumerable<TSource> Union<TSource>(IEnumerable<TSource> first, IEnumerable<TSource> second, IEqualityComparer<TSource> comparer)
EditExceptions
Throws an ArgumentNullException if
first or
second is null.
EditPseudo-code
Overload 1
If
first is null, throw an ArgumentNullException.
If
second is null, throw an ArgumentNullException.
Create a collection to hold elements we have already returned.
Iterate the
source sequence.
If the current element isn't in the already returned list (by using the default comparer EqualityComparer<TElement>.Default.
Add the current element to the already returned list.
Return the current element. Resume execution from this point when the next element is requested.
Overload 2
If
first is null, throw an ArgumentNullException.
If
second is null, throw an ArgumentNullException.
If
comparer is null, set the comparer to
EqualityComparer<TElement>.Default.
Iterate the
source sequence.
If the current element isn't in the already returned list by using the comparer function.
Add the current element to the already returned list.
Return the current element. Resume execution from this point when the next element is requested.
EditLoop count
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.