Click or drag to resize

MoreEnumerableSortedMergeTSource Method (IEnumerableTSource, OrderByDirection, IEnumerableTSource)

Merges two or more sequences that are in a common order (either ascending or descending) into a single sequence that preserves that order.

Namespace:  MoreLinq
Assembly:  MoreLinq (in MoreLinq.dll) Version: 2.3.0
Syntax
public static IEnumerable<TSource> SortedMerge<TSource>(
	this IEnumerable<TSource> source,
	OrderByDirection direction,
	params IEnumerable<TSource>[] otherSequences
)

Parameters

source
Type: System.Collections.GenericIEnumerableTSource
The primary sequence with which to merge
direction
Type: MoreLinqOrderByDirection
The ordering that all sequences must already exhibit
otherSequences
Type: System.Collections.GenericIEnumerableTSource
A variable argument array of zero or more other sequences to merge with

Type Parameters

TSource
The type of the elements of the sequence

Return Value

Type: IEnumerableTSource
A merged, order-preserving sequence containing all of the elements of the original sequences

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type IEnumerableTSource. 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
Using SortedMerge on sequences that are not ordered or are not in the same order produces undefined results.
SortedMerge uses performs the merge in a deferred, streaming manner.
Here is an example of a merge, as well as the produced result:
var s1 = new[] { 3, 7, 11 };
var s2 = new[] { 2, 4, 20 };
var s3 = new[] { 17, 19, 25 };
var merged = s1.SortedMerge( OrderByDirection.Ascending, s2, s3 );
var result = merged.ToArray();
// result will be:
// { 2, 3, 4, 7, 11, 17, 19, 20, 25 }
See Also