Editar

Compartilhar via


ArrayExtensions.GetColumn<T>(T[,], Int32) Method

Definition

Returns a RefEnumerable<T> that returns the items from a given column in a given 2D T array instance. This extension should be used directly within a foreach loop:

int[,] matrix =
{
    { 1, 2, 3 },
    { 4, 5, 6 },
    { 7, 8, 9 }
};

foreach (ref int number in matrix.GetColumn(1))
{
    // Access the current number by reference here...
}

The compiler will take care of properly setting up the foreach loop with the type returned from this method.

public static Microsoft.Toolkit.HighPerformance.Enumerables.RefEnumerable<T> GetColumn<T> (this T[,] array, int column);
static member GetColumn : 'T[,] * int -> Microsoft.Toolkit.HighPerformance.Enumerables.RefEnumerable<'T>
<Extension()>
Public Function GetColumn(Of T) (array As T(,), column As Integer) As RefEnumerable(Of T)

Type Parameters

T

The type of elements in the input 2D T array instance.

Parameters

array
T[,]

The input T array instance.

column
Int32

The target column to retrieve (0-based index).

Returns

A wrapper type that will handle the column enumeration for array.

Exceptions

Thrown when one of the input parameters is out of range.

Remarks

The returned RefEnumerable<T> value shouldn't be used directly: use this extension in a foreach loop.

Applies to