MoreEnumerableInterleaveT Method |
Interleaves the elements of two or more sequences into a single sequence, skipping sequences as they are consumed
Namespace:
MoreLinq
Assembly:
MoreLinq (in MoreLinq.dll) Version: 2.8.0
Syntax public static IEnumerable<T> Interleave<T>(
this IEnumerable<T> sequence,
params IEnumerable<T>[] otherSequences
)
<ExtensionAttribute>
Public Shared Function Interleave(Of T) (
sequence As IEnumerable(Of T),
ParamArray otherSequences As IEnumerable(Of T)()
) As IEnumerable(Of T)
public:
[ExtensionAttribute]
generic<typename T>
static IEnumerable<T>^ Interleave(
IEnumerable<T>^ sequence,
... array<IEnumerable<T>^>^ otherSequences
)
[<ExtensionAttribute>]
static member Interleave :
sequence : IEnumerable<'T> *
otherSequences : IEnumerable<'T>[] -> IEnumerable<'T>
Parameters
- sequence
- Type: System.Collections.GenericIEnumerableT
The first sequence in the interleave group - otherSequences
- Type: System.Collections.GenericIEnumerableT
The other sequences in the interleave group
Type Parameters
- T
- The type of the elements of the source sequences
Return Value
Type:
IEnumerableTA sequence of interleaved elements from all of the source sequences
Usage Note
In Visual Basic and C#, you can call this method as an instance method on any object of type
IEnumerableT. 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
Interleave combines sequences by visiting each in turn, and returning the first element of each, followed
by the second, then the third, and so on. So, for example:
{1,1,1}.Interleave( {2,2,2}, {3,3,3} ) => { 1,2,3,1,2,3,1,2,3 }
This operator behaves in a deferred and streaming manner.
When sequences are of unequal length, this method will skip those sequences that have been fully consumed
and continue interleaving the remaining sequences.
The sequences are interleaved in the order that they appear in the
otherSequences
collection, with
sequence as the first sequence.
See Also