Class ArrayEx
Class containing some extension methods for System.Array.
Inheritance
Inherited Members
Namespace:Extend
Assembly:Extend.dll
Syntax
public static class ArrayEx
Methods
| Improve this Doc View SourceClear(Array, Int32, Int32)
Sets a range of elements in the array to zero, to false, or to null, depending on the element type.
Declaration
public static void Clear(this Array array, int index, int length)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Array | array | The array whose elements need to be cleared. |
| System.Int32 | index | The starting index of the range of elements to clear. |
| System.Int32 | length | The number of elements to clear. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | array can not be null. |
Clear<T>(T[], Int32, Int32)
Sets a range of elements in the array to zero, to false, or to null, depending on the element type.
Declaration
public static T[] Clear<T>(this T[] array, int index, int length)
Parameters
| Type | Name | Description |
|---|---|---|
| T[] | array | The array whose elements need to be cleared. |
| System.Int32 | index | The starting index of the range of elements to clear. |
| System.Int32 | length | The number of elements to clear. |
Returns
| Type | Description |
|---|---|
| T[] | Returns the cleared array. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of the items in the array. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The array can not be null. |
ClearAll(Array)
Clears the given array.
Declaration
public static void ClearAll(this Array array)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Array | array | The array to clear. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The array can not be null. |
ClearAll<T>(T[])
Clears the given array.
Declaration
public static T[] ClearAll<T>(this T[] array)
Parameters
| Type | Name | Description |
|---|---|---|
| T[] | array | The array to clear. |
Returns
| Type | Description |
|---|---|
| T[] | Returns the cleared array. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of the items in the array. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The array can not be null. |
Copy(Array, Array, Int32)
Copies a range of elements from an array starting at the first element and pastes them into another array starting at the first element. The length is specified as a 32-bit integer.
Declaration
public static void Copy(this Array sourceArray, Array destinationArray, int length)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Array | sourceArray | The array that contains the data to copy. |
| System.Array | destinationArray | The array that receives the data. |
| System.Int32 | length | A 32-bit integer that represents the number of elements to copy. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | source array can not be null. |
| System.ArgumentNullException | destination array can not be null. |
Copy(Array, Int32, Array, Int32, Int32)
Copies a range of elements from an array starting at the specified source index and pastes them to another array starting at the specified destination index. The length and the indexes are specified as 32-bit integers.
Declaration
public static void Copy(this Array sourceArray, int sourceIndex, Array destinationArray, int destinationIndex, int length)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Array | sourceArray | The array that contains the data to copy. |
| System.Int32 | sourceIndex | A 32-bit integer that represents the index in the at which copying begins. |
| System.Array | destinationArray | The array that receives the data. |
| System.Int32 | destinationIndex | A 32-bit integer that represents the index in the at which storing begins. |
| System.Int32 | length | A 32-bit integer that represents the number of elements to copy. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | Source array can not be null. |
| System.ArgumentNullException | destination array can not be null. |
IndexOf(Array, Object)
Searches for the specified object and returns the index of its first occurrence in a one-dimensional array.
Declaration
public static int IndexOf(this Array array, object value)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Array | array | The one-dimensional to search. |
| System.Object | value | The object to locate in array. |
Returns
| Type | Description |
|---|---|
| System.Int32 | The index of the first occurrence of value in array, if found; otherwise, the lower bound of the array minus 1. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | Array can not be null. |
IndexOf(Array, Object, Int32)
Searches for the specified object in a range of elements of a one-dimensional array, and returns the index of its first occurrence. The range extends from a specified index to the end of the array.
Declaration
public static int IndexOf(this Array array, object value, int startIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Array | array | The one-dimensional to search. |
| System.Object | value | The object to locate in array. |
| System.Int32 | startIndex | The starting index of the search. 0 (zero) is valid in an empty array. |
Returns
| Type | Description |
|---|---|
| System.Int32 | The index of the first occurrence of value, if it’s found, within the range of elements in array that extends from startIndex to the last element; otherwise, the lower bound of the array minus 1. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | Array can not be null. |
IndexOf(Array, Object, Int32, Int32)
Searches for the specified object in a range of elements of a one-dimensional array, and returns the index of ifs first occurrence. The range extends from a specified index for a specified number of elements.
Declaration
public static int IndexOf(this Array array, object value, int startIndex, int count)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Array | array | The one-dimensional to search. |
| System.Object | value | The object to locate in array. |
| System.Int32 | startIndex | The starting index of the search. 0 (zero) is valid in an empty array. |
| System.Int32 | count | The number of elements to search. |
Returns
| Type | Description |
|---|---|
| System.Int32 | The index of the first occurrence of value, if it’s found, in the array from index startIndex to startIndex + count
|
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | Array can not be null. |
IndexOf<T>(T[], T)
Searches for the specified object and returns the index of its first occurrence in a one-dimensional array.
Declaration
public static int IndexOf<T>(this T[] array, T value)
Parameters
| Type | Name | Description |
|---|---|---|
| T[] | array | The one-dimensional to search. |
| T | value | The object to locate in array. |
Returns
| Type | Description |
|---|---|
| System.Int32 | The index of the first occurrence of within the entire , if found; otherwise, the lower bound of the array minus 1. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of the items in the array. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | Array can not be null. |
IndexOf<T>(T[], T, Int32)
Searches for the specified object in a range of elements of a one dimensional array, and returns the index of its first occurrence. The range extends from a specified index to the end of the array.
Declaration
public static int IndexOf<T>(this T[] array, T value, int startIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| T[] | array | The one-dimensional to search. |
| T | value | The object to locate in array. |
| System.Int32 | startIndex | The starting index of the search. 0 (zero) is valid in an empty array. |
Returns
| Type | Description |
|---|---|
| System.Int32 | The index of the first occurrence of within the range of elements in that extends from to the last element, if found; otherwise, the lower bound of the array minus 1. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of the items in the array. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | Array can not be null. |
IndexOf<T>(T[], T, Int32, Int32)
Searches for the specified object in a range of elements of a one-dimensional array, and returns the index of its first occurrence. The range extends from a specified index for a specified number of elements.
Declaration
public static int IndexOf<T>(this T[] array, T value, int startIndex, int count)
Parameters
| Type | Name | Description |
|---|---|---|
| T[] | array | The one-dimensional to search. |
| T | value | The object to locate in array. |
| System.Int32 | startIndex | The starting index of the search. 0 (zero) is valid in an empty array. |
| System.Int32 | count | The number of elements in the section to search. |
Returns
| Type | Description |
|---|---|
| System.Int32 | The index of the first occurrence of within the range of elements in that starts at and contains the number of elements specified in , if found; otherwise, the lower bound of the array minus 1. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of the items in the array. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | Array can not be null. |
LastIndexOf(Array, Object)
Searches for the specified object and returns the index of the last occurrence within the entire one-dimensional Array.
Declaration
public static int LastIndexOf(this Array array, object value)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Array | array | The one-dimensional to search. |
| System.Object | value | The object to locate in . |
Returns
| Type | Description |
|---|---|
| System.Int32 | The index of the last occurrence of within the entire , if found; otherwise, the lower bound of the array minus 1. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | Array can not be null. |
LastIndexOf(Array, Object, Int32)
Searches for the specified object and returns the index of the last occurrence within the range of elements in the one-dimensional Array that extends from the first element to the specified index.
Declaration
public static int LastIndexOf(this Array array, object value, int startIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Array | array | The one-dimensional to search. |
| System.Object | value | The object to locate in . |
| System.Int32 | startIndex | The starting index of the backward search. |
Returns
| Type | Description |
|---|---|
| System.Int32 | The index of the last occurrence of within the range of elements in that extends from the first element to , if found; otherwise, the lower bound of the array minus 1. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | Array can not be null. |
LastIndexOf(Array, Object, Int32, Int32)
Searches for the specified object and returns the index of the last occurrence within the range of elements in the one-dimensional Array that contains the specified number of elements and ends at the specified index.
Declaration
public static int LastIndexOf(this Array array, object value, int startIndex, int count)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Array | array | The one-dimensional to search. |
| System.Object | value | The object to locate in . |
| System.Int32 | startIndex | The starting index of the backward search. |
| System.Int32 | count | The number of elements in the section to search. |
Returns
| Type | Description |
|---|---|
| System.Int32 | The index of the last occurrence of within the range of elements in that contains the number of elements specified in and ends at , if found; otherwise, the lower bound of the array minus 1. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | Array can not be null. |
LastIndexOf<T>(T[], T)
Searches for the specified object and returns the index of the last occurrence within the entire
System.Array.
Declaration
public static int LastIndexOf<T>(this T[] array, T value)
Parameters
| Type | Name | Description |
|---|---|---|
| T[] | array | The one-dimensional to search. |
| T | value | The object to locate in . |
Returns
| Type | Description |
|---|---|
| System.Int32 | The index of the last occurrence of within the entire , if found; otherwise, the lower bound of the array minus 1. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of the items in the array. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | array can not be null. |
LastIndexOf<T>(T[], T, Int32)
Searches for the specified object and returns the index of the last occurrence within the range of elements in the
System.Array that extends from the first element to the specified index.
Declaration
public static int LastIndexOf<T>(this T[] array, T value, int startIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| T[] | array | The one-dimensional to search. |
| T | value | The object to locate in . |
| System.Int32 | startIndex | The starting index of the backward search. |
Returns
| Type | Description |
|---|---|
| System.Int32 | The index of the last occurrence of within the range of elements in that extends from the first element to , if found; otherwise, the lower bound of the array minus 1. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of the items in the array. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | array can not be null. |
LastIndexOf<T>(T[], T, Int32, Int32)
Searches for the specified object and returns the index of the last occurrence within the range of elements in the
System.Array that contains the specified number of elements and ends at the specified index.
Declaration
public static int LastIndexOf<T>(this T[] array, T value, int startIndex, int count)
Parameters
| Type | Name | Description |
|---|---|---|
| T[] | array | The one-dimensional to search. |
| T | value | The object to locate in . |
| System.Int32 | startIndex | The starting index of the backward search. |
| System.Int32 | count | The number of elements in the section to search. |
Returns
| Type | Description |
|---|---|
| System.Int32 | The index of the last occurrence of within the range of elements in that contains the number of elements specified in and ends at , if found; otherwise, the lower bound of the array minus 1. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of the items in the array. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | array can not be null. |
Populate<T>(T[], T)
Populates the given array with the specified value.
Declaration
public static T[] Populate<T>(this T[] array, T value)
Parameters
| Type | Name | Description |
|---|---|---|
| T[] | array | The array. |
| T | value | The value. |
Returns
| Type | Description |
|---|---|
| T[] | Returns the given array. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of the items in the array. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | array can not be null. |
Resize<T>(T[], Int32)
Resizes the given array to the specified size.
Declaration
public static T[] Resize<T>(this T[] array, int newSize)
Parameters
| Type | Name | Description |
|---|---|---|
| T[] | array | The array to resize. |
| System.Int32 | newSize | The new size of the array. |
Returns
| Type | Description |
|---|---|
| T[] | Returns the given array with the new size. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of the items in the array. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The array can not be null. |
Reverse(Array)
Reverses the sequence of the elements in the entire one-dimensional array.
Declaration
public static void Reverse(this Array array)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Array | array | The one-dimensional array to reverse. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | array can not be null. |
Reverse(Array, Int32, Int32)
Reverses the sequence of the elements in a range of elements in the one-dimensional array.
Declaration
public static void Reverse(this Array array, int index, int length)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Array | array | The one-dimensional array to reverse. |
| System.Int32 | index | The starting index of the section to reverse. |
| System.Int32 | length | The number of elements in the section to reverse. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | array can not be null. |
Reverse<T>(T[])
Reverses the sequence of the elements in the entire one-dimensional array.
Declaration
public static T[] Reverse<T>(this T[] array)
Parameters
| Type | Name | Description |
|---|---|---|
| T[] | array | The one-dimensional array to reverse. |
Returns
| Type | Description |
|---|---|
| T[] | Returns the reversed array. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of the items in the array. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The array can not be null. |
Reverse<T>(T[], Int32, Int32)
Reverses the sequence of the elements in a range of elements in the one-dimensional .
Declaration
public static T[] Reverse<T>(this T[] array, int index, int length)
Parameters
| Type | Name | Description |
|---|---|---|
| T[] | array | The one-dimensional array to reverse. |
| System.Int32 | index | The starting index of the section to reverse. |
| System.Int32 | length | The number of elements in the section to reverse. |
Returns
| Type | Description |
|---|---|
| T[] | Returns the reversed array. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of the items in the array. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | The array can not be null. |
Slice<T>(T[], Int32)
Copies the specified range of items from the source array to the given target array.
Declaration
public static T[] Slice<T>(this T[] array, int itemsToCpoy)
Parameters
| Type | Name | Description |
|---|---|---|
| T[] | array | The source array. |
| System.Int32 | itemsToCpoy | The number of items to copy, starting at the given start index. |
Returns
| Type | Description |
|---|---|
| T[] | Returns the target array. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of the items in the array. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | array can not be null. |
| System.ArgumentOutOfRangeException | The number of items to copy must be greater or equals to zero. |
| System.ArgumentOutOfRangeException | The number of items to copy cannot be greater than the length of the source array. |
Slice<T>(T[], Int32, T[])
Copies the specified range of items from the source array to the given target array.
Declaration
public static T[] Slice<T>(this T[] array, int itemsToCpoy, T[] targetArray)
Parameters
| Type | Name | Description |
|---|---|---|
| T[] | array | The source array. |
| System.Int32 | itemsToCpoy | The number of items to copy, starting at the given start index. |
| T[] | targetArray | The target array. |
Returns
| Type | Description |
|---|---|
| T[] | Returns the target array. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of the items in the array. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | array can not be null. |
| System.ArgumentNullException | targetArray can not be null. |
| System.ArgumentOutOfRangeException | The number of items to copy must be greater or equals to zero. |
| System.ArgumentOutOfRangeException | The number of items to copy cannot be greater than the length of the target array. |
| System.ArgumentOutOfRangeException | The number of items to copy cannot be greater than the length of the source array. |
Slice<T>(T[], Int32, Int32)
Copies the specified range of items from the source array to the given target array.
Declaration
public static T[] Slice<T>(this T[] array, int startIndex, int itemsToCpoy)
Parameters
| Type | Name | Description |
|---|---|---|
| T[] | array | The source array. |
| System.Int32 | startIndex | The start index of the items range. |
| System.Int32 | itemsToCpoy | The number of items to copy, starting at the given start index. |
Returns
| Type | Description |
|---|---|
| T[] | Returns the target array. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of the items in the array. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | array can not be null. |
| System.ArgumentNullException | targetArray can not be null. |
| System.ArgumentOutOfRangeException | The start index must be greater or equals to zero. |
| System.ArgumentOutOfRangeException | The number of items to copy must be greater or equals to zero. |
| System.ArgumentOutOfRangeException | The start index cannot be greater than the length of the given array. |
| System.ArgumentOutOfRangeException | The number of items to copy cannot be greater than the length of the source array (minus the start index). |
Slice<T>(T[], Int32, Int32, T[])
Copies the specified range of items from the source array to the given target array.
Declaration
public static T[] Slice<T>(this T[] array, int startIndex, int itemsToCpoy, T[] targetArray)
Parameters
| Type | Name | Description |
|---|---|---|
| T[] | array | The source array. |
| System.Int32 | startIndex | The start index of the items range. |
| System.Int32 | itemsToCpoy | The number of items to copy, starting at the given start index. |
| T[] | targetArray | The target array. |
Returns
| Type | Description |
|---|---|
| T[] | Returns the target array. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of the items in the array. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | array can not be null. |
| System.ArgumentNullException | targetArray can not be null. |
| System.ArgumentOutOfRangeException | The start index must be greater or equals to zero. |
| System.ArgumentOutOfRangeException | The number of items to copy must be greater or equals to zero. |
| System.ArgumentOutOfRangeException | The start index cannot be greater than the length of the given array. |
| System.ArgumentOutOfRangeException | The number of items to copy cannot be greater than the length of the target array. |
| System.ArgumentOutOfRangeException | The number of items to copy cannot be greater than the length of the source array (minus the start index). |
ToGenericList<TArray, TResult>(TArray[], Func<TArray, TResult>)
Converts the given array to a list using the specified selector.
Declaration
public static List<TResult> ToGenericList<TArray, TResult>(this TArray[] items, Func<TArray, TResult> selector)
Parameters
| Type | Name | Description |
|---|---|---|
| TArray[] | items | The array containing the items. |
| System.Func<T, TResult><TArray, TResult> | selector | The selector. |
Returns
| Type | Description |
|---|---|
| System.Collections.Generic.List<T><TResult> | The items of the array as list. |
Type Parameters
| Name | Description |
|---|---|
| TArray | The type of the items in the array. |
| TResult | The type of the items in the list. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | items can not be null. |
| System.ArgumentNullException | selector can not be null. |
ToList<T>(Array, Func<Object, T>)
Converts the given array to a list using the specified selector.
Declaration
public static List<T> ToList<T>(this Array items, Func<object, T> selector)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Array | items | The array containing the items. |
| System.Func<T, TResult><System.Object, T> | selector | The selector. |
Returns
| Type | Description |
|---|---|
| System.Collections.Generic.List<T><T> | The items of the array as list. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of the items in the list. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | items can not be null. |
| System.ArgumentNullException | selector can not be null. |
WithinIndex(Array, Int32)
Checks if the given index is within the array or not.
Declaration
public static bool WithinIndex(this Array array, int index)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Array | array | The array to check. |
| System.Int32 | index | a Zero-based index. |
Returns
| Type | Description |
|---|---|
| System.Boolean | Returns a value of true if the index is within the array, otherwise false. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | array can not be null. |