Table of Contents

Class GenericArrayExtensions

Namespace
Garyon.Extensions.ArrayExtensions
Assembly
Garyon.dll

Provides generic extension methods for arrays.

public static class GenericArrayExtensions
Inheritance
GenericArrayExtensions
Inherited Members

Methods

Clear(Array)

Clears the array by zeroing out all its elements. This affects the original instance.

public static void Clear(this Array array)

Parameters

array Array

The array to clear.

CopyArray<T>(T[])

Copies the original array and returns a new array which contains the same elements at the same indices.

public static T[] CopyArray<T>(this T[] array)

Parameters

array T[]

The original array to copy.

Returns

T[]

Type Parameters

T

The type of the array elements.

Fill<T>(T[], T)

Assigns the given value of type T to each element of the specified array. This affects the original instance.

public static void Fill<T>(this T[] array, T value)

Parameters

array T[]

The array to be filled.

value T

The value to assign to each array element.

Type Parameters

T

GetDimensionLengths(Array)

Gets the lengths of the array's dimensions.

public static int[] GetDimensionLengths(this Array array)

Parameters

array Array

The array whose dimension lengths to get.

Returns

int[]

An int[] containing the dimension lengths in order.

IsArrayOfType<TElement>(Array)

Determines whether an array type contains elements of the provided type. It only checks for multidimensional arrays (of the form [(,)*]). Jagged arrays are not taken into consideration in this implementation. Also built as an extension method to allow per-instance call.

public static bool IsArrayOfType<TElement>(this Array array)

Parameters

array Array

The array whose type to examine.

Returns

bool

Whether the given array type stores elements of the TElement type.

Type Parameters

TElement

The type of the element the array stores.

IsArrayOfType<TElement>(Array, int)

Determines whether an array type contains elements of the provided type. It also checks for jagged arrays up to a maximum jagging level. Also built as an extension method to allow per-instance call.

public static bool IsArrayOfType<TElement>(this Array array, int maxJaggingLevel)

Parameters

array Array

The array whose type to examine.

maxJaggingLevel int

The maximum jagging level of the array (1 means up to [], 2 means up to [][], etc.).

Returns

bool

Whether the given array type stores elements of the TElement type.

Type Parameters

TElement

The type of the element the array stores.

MoveElementToEnd<T>(T[], int)

Moves an array element at a specified index to the end of the array. This affects the original array and returns its instance.

public static T[] MoveElementToEnd<T>(this T[] array, int from)

Parameters

array T[]

The original array whose element to move.

from int

The old index of the element to move.

Returns

T[]

Type Parameters

T

The type of the array elements.

MoveElementToStart<T>(T[], int)

Moves an array element at a specified index to the start of the array. This affects the original array and returns its instance.

public static T[] MoveElementToStart<T>(this T[] array, int from)

Parameters

array T[]

The original array whose element to move.

from int

The old index of the element to move.

Returns

T[]

Type Parameters

T

The type of the array elements.

MoveElement<T>(T[], int, int)

Moves an array element at a specified index to another. This affects the original array and returns its instance.

public static T[] MoveElement<T>(this T[] array, int from, int to)

Parameters

array T[]

The original array whose element to move.

from int

The old index of the element to move.

to int

The new index of the element to move.

Returns

T[]

Type Parameters

T

The type of the array elements.

Reverse<T>(T[])

Reverses the elements of the array. Returns the instance of the original array.

public static T[] Reverse<T>(this T[] array)

Parameters

array T[]

The original array to reverse.

Returns

T[]

Type Parameters

T

The type of the array elements.

SegmentFromBounds<T>(T[], int, int)

Creates an ArraySegment<T> that reflects a subset of the array's range.

public static ArraySegment<T> SegmentFromBounds<T>(this T[] array, int start, int end)

Parameters

array T[]

The array whose segment to get.

start int

The starting index within the array, inclusive.

end int

The end index of the array, exclusive.

Returns

ArraySegment<T>

Type Parameters

T

Segment<T>(T[])

Creates an ArraySegment<T> that reflects the entire array's range.

public static ArraySegment<T> Segment<T>(this T[] array)

Parameters

array T[]

Returns

ArraySegment<T>

Type Parameters

T

Segment<T>(T[], int, int)

Creates an ArraySegment<T> that reflects a subset of the array's range.

public static ArraySegment<T> Segment<T>(this T[] array, int start, int count)

Parameters

array T[]
start int
count int

Returns

ArraySegment<T>

Type Parameters

T

Swap<T>(T[], int, int)

Swaps two elements in the array. Returns the instance of the original array.

public static T[] Swap<T>(this T[] array, int a, int b)

Parameters

array T[]

The array whose elements to swap.

a int

The index of the first element to swap.

b int

The index of the second element to swap.

Returns

T[]

Type Parameters

T

The type of the array elements.