Editar

Compartilhar via


ArrayExtensions Class

Definition

Helpers for working with the Array type.

public static class ArrayExtensions
type ArrayExtensions = class
Public Module ArrayExtensions
Inheritance
ArrayExtensions

Methods

Count<T>(T[,], T)

Counts the number of occurrences of a given value into a target 2D T array instance.

Count<T>(T[], T)

Counts the number of occurrences of a given value into a target T array instance.

DangerousGetReference<T>(T[,])

Returns a reference to the first element within a given 2D T array, with no bounds checks.

DangerousGetReference<T>(T[])

Returns a reference to the first element within a given T array, with no bounds checks.

DangerousGetReferenceAt<T>(T[,], Int32, Int32)

Returns a reference to an element at a specified coordinate within a given 2D T array, with no bounds checks.

DangerousGetReferenceAt<T>(T[], Int32)

Returns a reference to an element at a specified index within a given T array, with no bounds checks.

Enumerate<T>(T[])

Enumerates the items in the input T array instance, as pairs of reference/index values. This extension should be used directly within a foreach loop:

int[] numbers = new[] { 1, 2, 3, 4, 5, 6, 7 };

foreach (var item in numbers.Enumerate())
{
    // Access the index and value of each item here...
    int index = item.Index;
    ref int value = ref item.Value;
}

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

Fill<T>(T[,], T, Int32, Int32, Int32, Int32)

Fills an area in a given 2D T array instance with a specified value. This API will try to fill as many items as possible, ignoring positions outside the bounds of the array. If invalid coordinates are given, they will simply be ignored and no exception will be thrown.

GetColumn<T>(T[,], Int32)

Returns an enumerable 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.

GetDjb2HashCode<T>(T[,])

Gets a content hash from the input 2D T array instance using the Djb2 algorithm. For more info, see the documentation for GetDjb2HashCode<T>(ReadOnlySpan<T>).

GetDjb2HashCode<T>(T[])

Gets a content hash from the input T array instance using the Djb2 algorithm. For more info, see the documentation for GetDjb2HashCode<T>(ReadOnlySpan<T>).

GetRow<T>(T[,], Int32)

Returns a Span<T> over a row in a given 2D T array instance.

Tokenize<T>(T[], T)

Tokenizes the values in the input T array instance using a specified separator. This extension should be used directly within a foreach loop:

char[] text = "Hello, world!".ToCharArray();

foreach (var token in text.Tokenize(','))
{
    // Access the tokens here...
}

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

Applies to