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
arrayArrayThe 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
arrayT[]The original array to copy.
Returns
- T[]
Type Parameters
TThe 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
arrayT[]The array to be filled.
valueTThe 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
arrayArrayThe array whose dimension lengths to get.
Returns
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
arrayArrayThe array whose type to examine.
Returns
- bool
Whether the given array type stores elements of the
TElementtype.
Type Parameters
TElementThe 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
arrayArrayThe array whose type to examine.
maxJaggingLevelintThe 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
TElementtype.
Type Parameters
TElementThe 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
arrayT[]The original array whose element to move.
fromintThe old index of the element to move.
Returns
- T[]
Type Parameters
TThe 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
arrayT[]The original array whose element to move.
fromintThe old index of the element to move.
Returns
- T[]
Type Parameters
TThe 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
arrayT[]The original array whose element to move.
fromintThe old index of the element to move.
tointThe new index of the element to move.
Returns
- T[]
Type Parameters
TThe 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
arrayT[]The original array to reverse.
Returns
- T[]
Type Parameters
TThe 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
arrayT[]The array whose segment to get.
startintThe starting index within the array, inclusive.
endintThe 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
arrayT[]
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
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
arrayT[]The array whose elements to swap.
aintThe index of the first element to swap.
bintThe index of the second element to swap.
Returns
- T[]
Type Parameters
TThe type of the array elements.