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.3.1+b77df70598ab84c28cd43dcf74594024b6d575e1
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