Click or drag to resize

MoreEnumerableTransposeT Method

Transposes a sequence of rows into a sequence of columns.

Namespace:  MoreLinq
Assembly:  MoreLinq (in MoreLinq.dll) Version: 3.2.0+5205ea241d72b079436060d330cd5c2eae7cdcdf
Syntax
public static IEnumerable<IEnumerable<T>> Transpose<T>(
	this IEnumerable<IEnumerable<T>> source
)

Parameters

source
Type: System.Collections.GenericIEnumerableIEnumerableT
Source sequence to transpose.

Type Parameters

T
Type of source sequence elements.

Return Value

Type: IEnumerableIEnumerableT
Returns a sequence of columns in the source swapped into rows.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type IEnumerableIEnumerableT. 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
If a rows is shorter than a follow it then the shorter row's elements are skipped in the corresponding column sequences. This operator uses deferred execution and streams its results. Source sequence is consumed greedily when an iteration begins. The inner sequences representing rows are consumed lazily and resulting sequences of columns are streamed.
Examples
var matrix = new[]
{
    new[] { 10, 11 },
    new[] { 20 },
    new[] { 30, 31, 32 }
};
var result = matrix.Transpose();
The result variable will contain [[10, 20, 30], [11, 31], [32]].
See Also