Class ArrayHelper
Utility class for common array operations.
public static class ArrayHelper
- Inheritance
-
ArrayHelper
- Inherited Members
Methods
Clear(Array)
Sets all of the elements in the specified Array to zero, false, or null, depending on the element type.
public static void Clear(this Array array)
Parameters
array
ArrayThe array whose elements need to be cleared.
Exceptions
- ArgumentNullException
Thrown when the array is null.
Clear(Array, int, int)
Sets a range of elements in the specified Array to zero, false, or null, depending on the element type.
public static void Clear(this Array array, int index, int count)
Parameters
array
ArrayThe array whose elements need to be cleared.
index
intThe starting index of the range of elements to clear.
count
intThe number of elements to clear.
Exceptions
- ArgumentNullException
Thrown when the array is null.
Clone<T>(T[])
Creates a shallow copy of the specified array.
public static T[] Clone<T>(this T[] array)
Parameters
array
T[]The source array.
Returns
- T[]
A new array that is a shallow copy of the source array.
Type Parameters
T
The type of elements in the array.
Exceptions
- ArgumentNullException
Thrown when the array is null.
Concat<T>(T[], T[])
Concatenates two arrays into a single new array.
public static T[] Concat<T>(this T[] first, T[] second)
Parameters
first
T[]The first array to concatenate.
second
T[]The second array to concatenate.
Returns
- T[]
A new array that contains the elements of the first array followed by the elements of the second array.
Type Parameters
T
The type of elements in the arrays.
Exceptions
- ArgumentNullException
Thrown when either of the arrays is null.
CopyArray<T>(ICollection<T>)
Creates a copy of the elements from the specified collection into a new array.
public static T[] CopyArray<T>(this ICollection<T> source)
Parameters
source
ICollection<T>The source collection.
Returns
- T[]
A new array containing the elements of the source collection.
Type Parameters
T
The type of elements in the collection.
Exceptions
- ArgumentNullException
Thrown when the source collection is null.
CopyArray<T>(T[])
Creates a copy of the source array.
public static T[] CopyArray<T>(this T[] source)
Parameters
source
T[]The source array.
Returns
- T[]
A new array containing the same elements as the source array.
Type Parameters
T
The type of elements in the array.
Exceptions
- ArgumentNullException
Thrown when the source array is null.
CreateArray(Type, int)
public static Array CreateArray(this Type type, int count)
Parameters
Returns
- Array
A new array of the specified type and length.
IndexOf<T>(T[], T)
Searches for the specified object and returns the index of the first occurrence within the entire one-dimensional array.
public static int IndexOf<T>(this T[] array, T item)
Parameters
array
T[]The one-dimensional array to search.
item
TThe object to locate in the array.
Returns
- int
The index of the first occurrence of value within the entire array, if found; otherwise, the lower bound of the array minus 1.
Type Parameters
T
The type of elements in the array.
Range<T>(T[], int)
Returns a subarray that starts at the specified index and extends to the end of the array.
public static T[] Range<T>(this T[] array, int index)
Parameters
array
T[]The source array.
index
intThe starting index of the subarray.
Returns
- T[]
A new array containing the elements from the specified index to the end of the source array.
Type Parameters
T
The type of elements in the array.
Exceptions
- ArgumentNullException
Thrown when the array is null.
Range<T>(T[], int, int)
Returns a subarray that begins at the specified index and contains the specified number of elements.
public static T[] Range<T>(this T[] array, int index, int count)
Parameters
array
T[]The source array.
index
intThe starting index of the subarray.
count
intThe number of elements to include in the subarray.
Returns
- T[]
A new array containing the specified range of elements from the source array.
Type Parameters
T
The type of elements in the array.
Reverse<T>(T[])
Returns a reversed copy of the specified array.
public static T[] Reverse<T>(this T[] array)
Parameters
array
T[]The source array.
Returns
- T[]
A new array with the elements in reverse order.
Type Parameters
T
The type of elements in the array.
Exceptions
- ArgumentNullException
Thrown when the array is null.