Class Array
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the base class for all arrays in the common language runtime.
Inherited Members
Namespace: System
Assembly: mscorlib.dll
Syntax
public abstract class Array : ICloneable, IList, ICollection, IEnumerable
Properties
| Improve this Doc View SourceIsFixedSize
Gets a value indicating whether the Array has a fixed size.
Declaration
public bool IsFixedSize { get; }
Property Value
Type | Description |
---|---|
Boolean | This property is always true for all arrays. |
IsReadOnly
Gets a value indicating whether the Array is read-only.
Declaration
public bool IsReadOnly { get; }
Property Value
Type | Description |
---|---|
Boolean | This property is always false for all arrays. |
IsSynchronized
Gets a value indicating whether access to the Array is synchronized (thread safe).
Declaration
public bool IsSynchronized { get; }
Property Value
Type | Description |
---|---|
Boolean | This property is always false for all arrays. |
Length
Gets a 32-bit integer that represents the total number of elements in all the dimensions of the Array.
Declaration
public int Length { get; }
Property Value
Type | Description |
---|---|
Int32 | A 32-bit integer that represents the total number of elements in all the dimensions of the Array; zero if there are no elements in the array. |
SyncRoot
Gets an object that can be used to synchronize access to the Array.
Declaration
public object SyncRoot { get; }
Property Value
Type | Description |
---|---|
Object | An object that can be used to synchronize access to the Array. |
Methods
| Improve this Doc View SourceBinarySearch(Array, Int32, Int32, Object, IComparer)
Searches a range of elements in a one-dimensional sorted Array for a value, using the specified IComparer interface.
Declaration
public static int BinarySearch(Array array, int index, int length, object value, IComparer comparer)
Parameters
Type | Name | Description |
---|---|---|
Array | array | The sorted one-dimensional Array to search. |
Int32 | index | The starting index of the range to search. |
Int32 | length | The length of the range to search. |
Object | value | The object to search for. |
IComparer | comparer | The IComparer implementation to use when comparing elements. -or- nullNothingnullptrunit a null reference(Nothing in Visual Basic) to use the IComparable implementation of each element. |
Returns
Type | Description |
---|---|
Int32 | The index of the specified value in the specified array, if value is found. If value is not found and value is less than one or more elements in array, a negative number which is the bitwise complement of the index of the first element that is larger than value. If value is not found and value is greater than any of the elements in array, a negative number which is the bitwise complement of (the index of the last element plus 1). |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | comparer is null reference (Nothing in Visual Basic), value does not implement the IComparable interface, and the search encounters an element that does not implement the IComparable interface. |
BinarySearch(Array, Object, IComparer)
Searches an entire one-dimensional sorted Array for a value using the specified IComparer interface.
Declaration
public static int BinarySearch(Array array, object value, IComparer comparer)
Parameters
Type | Name | Description |
---|---|---|
Array | array | The sorted one-dimensional Array to search. |
Object | value | The object to search for. |
IComparer | comparer | The IComparer implementation to use when comparing elements. -or- nullNothingnullptrunit a null reference(Nothing in Visual Basic) to use the IComparable implementation of each element. |
Returns
Type | Description |
---|---|
Int32 | The index of the specified value in the specified array, if value is found. If value is not found and value is less than one or more elements in array, a negative number which is the bitwise complement of the index of the first element that is larger than value. If value is not found and value is greater than any of the elements in array, a negative number which is the bitwise complement of (the index of the last element plus 1). |
Clear(Array, Int32, Int32)
Sets a range of elements in the Array to zero, to false, or to null reference (Nothing in Visual Basic), depending on the element type.
Declaration
public static extern void Clear(Array array, int index, int length)
Parameters
Type | Name | Description |
---|---|---|
Array | array | The Array whose elements need to be cleared. |
Int32 | index | The starting index of the range of elements to clear. |
Int32 | length | The number of elements to clear. |
Clone()
Creates a shallow copy of the Array.
Declaration
public object Clone()
Returns
Type | Description |
---|---|
Object | A shallow copy of the Array. |
Remarks
Available only in mscorlib build with support for System.Reflection.
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(Array sourceArray, Array destinationArray, int length)
Parameters
Type | Name | Description |
---|---|---|
Array | sourceArray | The Array that contains the data to copy. |
Array | destinationArray | The Array that receives the data. |
Int32 | length | A 32-bit integer that represents the number of elements to copy. |
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 extern void Copy(Array sourceArray, int sourceIndex, Array destinationArray, int destinationIndex, int length)
Parameters
Type | Name | Description |
---|---|---|
Array | sourceArray | The Array that contains the data to copy. |
Int32 | sourceIndex | A 32-bit integer that represents the index in the sourceArray at which copying begins. |
Array | destinationArray | The Array that receives the data. |
Int32 | destinationIndex | A 32-bit integer that represents the index in the destinationArray at which storing begins. |
Int32 | length | A 32-bit integer that represents the number of elements to copy. |
CopyTo(Array, Int32)
Copies all the elements of the current one-dimensional Array to the specified one-dimensional Array starting at the specified destination Array index. The index is specified as a 32-bit integer.
Declaration
public void CopyTo(Array array, int index)
Parameters
Type | Name | Description |
---|---|---|
Array | array | The one-dimensional Array that is the destination of the elements copied from the current Array. |
Int32 | index | A 32-bit integer that represents the index in array at which copying begins. |
CreateInstance(Type, Int32)
Creates a one-dimensional Array of the specified Type and length, with zero-based indexing.
Declaration
public static extern Array CreateInstance(Type elementType, int length)
Parameters
Type | Name | Description |
---|---|---|
Type | elementType | The Type of the Array to create. |
Int32 | length | The size of the Array to create. |
Returns
Type | Description |
---|---|
Array | A new one-dimensional Array of the specified Type with the specified length, using zero-based indexing. |
Remarks
Unlike most classes, Array provides the CreateInstance method, instead of public constructors, to allow for late bound access.
Reference-type elements are initialized to nullNothingnullptrunit a null reference(Nothing in Visual Basic). Value-type elements are initialized to zero.
This method is an O(n) operation, where n is length.
Available only in mscorlib build with support for System.Reflection.GetEnumerator()
Returns an IEnumerator for the Array.
Declaration
public IEnumerator GetEnumerator()
Returns
Type | Description |
---|---|
IEnumerator | An IEnumerator for the Array. |
GetValue(Int32)
Gets the value at the specified position in the one-dimensional Array. The index is specified as a 32-bit integer.
Declaration
public object GetValue(int index)
Parameters
Type | Name | Description |
---|---|---|
Int32 | index | A 32-bit integer that represents the position of the Array element to get. |
Returns
Type | Description |
---|---|
Object | The value at the specified position in the one-dimensional Array. |
IndexOf(Array, Object)
Searches for the specified object and returns the index of the first occurrence within the entire one-dimensional Array.
Declaration
public static int IndexOf(Array array, object value)
Parameters
Type | Name | Description |
---|---|---|
Array | array | The one-dimensional Array to search. |
Object | value | The object to locate in array. |
Returns
Type | Description |
---|---|
Int32 | The index of the first occurrence of value within the entire array, if found; otherwise, the lower bound of the array minus 1. |
IndexOf(Array, Object, Int32)
Searches for the specified object and returns the index of the first occurrence within the range of elements in the one-dimensional Array that extends from the specified index to the last element.
Declaration
public static int IndexOf(Array array, object value, int startIndex)
Parameters
Type | Name | Description |
---|---|---|
Array | array | The one-dimensional Array to search. |
Object | value | The object to locate in array. |
Int32 | startIndex | The starting index of the search. 0 (zero) is valid in an empty array. |
Returns
Type | Description |
---|---|
Int32 | The index of the first occurrence of value within the range of elements in array that extends from startIndex to the last element, if found; otherwise, the lower bound of the array minus 1. |
IndexOf(Array, Object, Int32, Int32)
Searches for the specified object and returns the index of the first occurrence within the range of elements in the one-dimensional Array that starts at the specified index and contains the specified number of elements.
Declaration
public static int IndexOf(Array array, object value, int startIndex, int count)
Parameters
Type | Name | Description |
---|---|---|
Array | array | The one-dimensional Array to search. |
Object | value | The object to locate in array. |
Int32 | startIndex | The starting index of the search. 0 (zero) is valid in an empty array. |
Int32 | count | The number of elements in the section to search. |
Returns
Type | Description |
---|---|
Int32 | The index of the first occurrence of value within the range of elements in array that starts at startIndex and contains the number of elements specified in count, if found; otherwise, the lower bound of the array minus 1. |
Explicit Interface Implementations
| Improve this Doc View SourceICollection.Count
Declaration
int ICollection.Count { get; }
Returns
Type | Description |
---|---|
Int32 |
IList.Add(Object)
Declaration
int IList.Add(object value)
Parameters
Type | Name | Description |
---|---|---|
Object | value |
Returns
Type | Description |
---|---|
Int32 |
IList.Clear()
Declaration
void IList.Clear()
IList.Contains(Object)
Declaration
bool IList.Contains(object value)
Parameters
Type | Name | Description |
---|---|---|
Object | value |
Returns
Type | Description |
---|---|
Boolean |
IList.IndexOf(Object)
Declaration
int IList.IndexOf(object value)
Parameters
Type | Name | Description |
---|---|---|
Object | value |
Returns
Type | Description |
---|---|
Int32 |
IList.Insert(Int32, Object)
Declaration
void IList.Insert(int index, object value)
Parameters
Type | Name | Description |
---|---|---|
Int32 | index | |
Object | value |
IList.Item[Int32]
Declaration
object IList.this[int index] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
Int32 | index |
Returns
Type | Description |
---|---|
Object |
IList.Remove(Object)
Declaration
void IList.Remove(object value)
Parameters
Type | Name | Description |
---|---|---|
Object | value |
IList.RemoveAt(Int32)
Declaration
void IList.RemoveAt(int index)
Parameters
Type | Name | Description |
---|---|---|
Int32 | index |