Enumerable.UnionBy Method (System.Linq) (original) (raw)

Source:

Union.cs

Source:

Union.cs

Source:

Union.cs

Source:

Union.cs

Produces the set union of two sequences according to a specified key selector function.

public:
generic <typename TSource, typename TKey>
[System::Runtime::CompilerServices::Extension]
 static System::Collections::Generic::IEnumerable<TSource> ^ UnionBy(System::Collections::Generic::IEnumerable<TSource> ^ first, System::Collections::Generic::IEnumerable<TSource> ^ second, Func<TSource, TKey> ^ keySelector, System::Collections::Generic::IEqualityComparer<TKey> ^ comparer);
public static System.Collections.Generic.IEnumerable<TSource> UnionBy<TSource,TKey>(this System.Collections.Generic.IEnumerable<TSource> first, System.Collections.Generic.IEnumerable<TSource> second, Func<TSource,TKey> keySelector, System.Collections.Generic.IEqualityComparer<TKey>? comparer);
static member UnionBy : seq<'Source> * seq<'Source> * Func<'Source, 'Key> * System.Collections.Generic.IEqualityComparer<'Key> -> seq<'Source>
<Extension()>
Public Function UnionBy(Of TSource, TKey) (first As IEnumerable(Of TSource), second As IEnumerable(Of TSource), keySelector As Func(Of TSource, TKey), comparer As IEqualityComparer(Of TKey)) As IEnumerable(Of TSource)

Type Parameters

TSource

The type of the elements of the input sequences.

TKey

The type of key to identify elements by.

Parameters

keySelector

Func<TSource,TKey>

A function to extract the key for each element.

Returns

An IEnumerable that contains the elements from both input sequences, excluding duplicates.

Exceptions

Remarks

This method is implemented by using deferred execution. The immediate return value is an object that stores all the information that is required to perform the action. The query represented by this method is not executed until the object is enumerated either by calling its GetEnumerator method directly or by using foreach in C# or For Each in Visual Basic.

If comparer is null, the default equality comparer, Default, is used to compare values.

When the object returned by this method is enumerated, UnionBy enumerates first and second in that order and yields each element that has not already been yielded.

See also

Applies to