Edytuj

Udostępnij za pośrednictwem


ArrayExtensions Class

Definition

Helpers for working with the Array type.

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

Methods

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

Creates a new instance of the Memory<T> struct wrapping a layer in a 3D array.

AsMemory<T>(T[,,])

Creates a new Memory<T> over an input 3D T array.

AsMemory<T>(T[,])

Creates a new Memory<T> over an input 2D T array.

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

Creates a new instance of the Memory2D<T> struct wrapping a layer in a 3D array.

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

Creates a new Memory2D<T> over an input 2D T array.

AsMemory2D<T>(T[,])

Creates a new Memory2D<T> over an input 2D T array.

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

Creates a new instance of the Span<T> struct wrapping a layer in a 3D array.

AsSpan<T>(T[,,])

Creates a new Span<T> over an input 3D T array.

AsSpan<T>(T[,])

Creates a new Span<T> over an input 2D T array.

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

Creates a new instance of the Span2D<T> struct wrapping a layer in a 3D array.

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

Creates a new Span2D<T> over an input 2D T array.

AsSpan2D<T>(T[,])

Creates a new Span2D<T> over an input 2D T array.

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

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

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 3D T array, with no bounds checks.

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, Int32)

Returns a reference to an element at a specified coordinate within a given 3D 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.

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

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.

GetDjb2HashCode<T>(T[,,])

Gets a content hash from the input 3D 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 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 RefEnumerable<T> over a row in a given 2D T array instance.

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

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

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

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

IsCovariant<T>(T[,,])

Checks whether or not a given T array is covariant.

IsCovariant<T>(T[,])

Checks whether or not a given T array is covariant.

IsCovariant<T>(T[])

Checks whether or not a given T array is covariant.

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