OrderedMergeExtensionOrderedMergeTFirst, TSecond, TKey, TResult(IEnumerableTFirst, IEnumerableTSecond, FuncTFirst, TKey, FuncTSecond, TKey, FuncTFirst, TResult, FuncTSecond, TResult, FuncTFirst, TSecond, TResult, IComparerTKey) Method

Merges two heterogeneous sequences ordered by a common key type into a homogeneous one. Additional parameters specify the element key by which the sequences are ordered, the result when element is found in first sequence but not in the second, the result when element is found in second sequence but not in the first, the result when elements are found in both sequences and a method for comparing keys.

Definition

Namespace: MoreLinq.Extensions
Assembly: MoreLinq (in MoreLinq.dll) Version: 4.1.0+0e154ef592f33ce0f6f3d534a9eedee273f0ce72
C#
public static IEnumerable<TResult> OrderedMerge<TFirst, TSecond, TKey, TResult>(
	this IEnumerable<TFirst> first,
	IEnumerable<TSecond> second,
	Func<TFirst, TKey> firstKeySelector,
	Func<TSecond, TKey> secondKeySelector,
	Func<TFirst, TResult> firstSelector,
	Func<TSecond, TResult> secondSelector,
	Func<TFirst, TSecond, TResult> bothSelector,
	IComparer<TKey>? comparer
)

Parameters

first  IEnumerableTFirst
The first input sequence.
second  IEnumerableTSecond
The second input sequence.
firstKeySelector  FuncTFirst, TKey
Function to extract a key given an element from the first sequence.
secondKeySelector  FuncTSecond, TKey
Function to extract a key given an element from the second sequence.
firstSelector  FuncTFirst, TResult
Function to project the result element when only the first sequence yields a source element.
secondSelector  FuncTSecond, TResult
Function to project the result element when only the second sequence yields a source element.
bothSelector  FuncTFirst, TSecond, TResult
Function to project the result element when only both sequences yield a source element whose keys are equal.
comparer  IComparerTKey
An IComparerT to compare keys.

Type Parameters

TFirst
Type of elements in the first sequence.
TSecond
Type of elements in the second sequence.
TKey
Type of keys used for merging.
TResult
Type of elements in the returned sequence.

Return Value

IEnumerableTResult
A sequence with projections from the two input sequences merged according to a key, as in a full outer join.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type IEnumerableTFirst. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).

Remarks

This method uses deferred execution. The behavior is undefined if the sequences are unordered (by key) as inputs.

See Also