TransposeExtensionTransposeT Method
Transposes a sequence of rows into a sequence of columns.
Namespace: MoreLinq.ExtensionsAssembly: MoreLinq (in MoreLinq.dll) Version: 3.4.0+b99a6a8cc504caf2d48372fe54a2f8116c59cd0c
public static IEnumerable<IEnumerable<T>> Transpose<T>(
this IEnumerable<IEnumerable<T>> source
)
<ExtensionAttribute>
Public Shared Function Transpose(Of T) (
source As IEnumerable(Of IEnumerable(Of T))
) As IEnumerable(Of IEnumerable(Of T))
public:
[ExtensionAttribute]
generic<typename T>
static IEnumerable<IEnumerable<T>^>^ Transpose(
IEnumerable<IEnumerable<T>^>^ source
)
[<ExtensionAttribute>]
static member Transpose :
source : IEnumerable<IEnumerable<'T>> -> IEnumerable<IEnumerable<'T>>
- source IEnumerableIEnumerableT
- Source sequence to transpose.
- T
- Type of source sequence elements.
IEnumerableIEnumerableT
Returns a sequence of columns in the source swapped into rows.
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).
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.
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]].