Array Class

Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the base class for all arrays in the common language runtime.

To browse the .NET Framework source code for this type, see the Reference Source.

Namespace:  System
Assemblies:   System.Runtime (in System.Runtime.dll)
  mscorlib (in mscorlib.dll)

public ref class Array abstract : IList, 
	ICollection, IEnumerable, IStructuralComparable, IStructuralEquatable

The Array type exposes the following members.

  NameDescription
Public propertySupported by the XNA FrameworkIsFixedSizeGets a value indicating whether the Array has a fixed size.
Public propertySupported by the XNA FrameworkIsReadOnlyGets a value indicating whether the Array is read-only.
Public propertySupported by the XNA FrameworkIsSynchronizedGets a value indicating whether access to the Array is synchronized (thread safe).
Public propertySupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsLengthGets a 32-bit integer that represents the total number of elements in all the dimensions of the Array.
Public propertyLongLengthGets a 64-bit integer that represents the total number of elements in all the dimensions of the Array.
Public propertySupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsRankGets the rank (number of dimensions) of the Array. For example, a one-dimensional array returns 1, a two-dimensional array returns 2, and so on.
Public propertySupported by the XNA FrameworkSyncRootGets an object that can be used to synchronize access to the Array.
Top

  NameDescription
Public methodStatic memberAsReadOnly<T>Returns a read-only wrapper for the specified array.
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsBinarySearch(Array, Object)Searches an entire one-dimensional sorted array for a specific element, using the IComparable interface implemented by each element of the array and by the specified object.
Public methodStatic memberSupported by Portable Class LibrarySupported in .NET for Windows Store appsBinarySearch(Array, Object, IComparer)Searches an entire one-dimensional sorted array for a value using the specified IComparer interface.
Public methodStatic memberSupported by Portable Class LibrarySupported in .NET for Windows Store appsBinarySearch(Array, Int32, Int32, Object)Searches a range of elements in a one-dimensional sorted array for a value, using the IComparable interface implemented by each element of the array and by the specified value.
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsBinarySearch(Array, Int32, Int32, Object, IComparer)Searches a range of elements in a one-dimensional sorted array for a value, using the specified IComparer interface.
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsBinarySearch<T>(array<T>, T)Searches an entire one-dimensional sorted array for a specific element, using the IComparable<T> generic interface implemented by each element of the Array and by the specified object.
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsBinarySearch<T>(array<T>, T, IComparer<T>)Searches an entire one-dimensional sorted array for a value using the specified IComparer<T> generic interface.
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsBinarySearch<T>(array<T>, Int32, Int32, T)Searches a range of elements in a one-dimensional sorted array for a value, using the IComparable<T> generic interface implemented by each element of the Array and by the specified value.
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsBinarySearch<T>(array<T>, Int32, Int32, T, IComparer<T>)Searches a range of elements in a one-dimensional sorted array for a value, using the specified IComparer<T> generic interface.
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsClearSets a range of elements in an array to the default value of each element type.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsCloneCreates a shallow copy of the Array.
Public methodStatic memberSupported by Portable Class LibrarySupported in .NET for Windows Store appsConstrainedCopyCopies 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. Guarantees that all changes are undone if the copy does not succeed completely.
Public methodStatic memberConvertAll<TInput, TOutput>Converts an array of one type to an array of another type.
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsCopy(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.
Public methodStatic memberCopy(Array, Array, Int64)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 64-bit integer.
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsCopy(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.
Public methodStatic memberCopy(Array, Int64, Array, Int64, Int64)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 64-bit integers.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsCopyTo(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.
Public methodCopyTo(Array, Int64)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 64-bit integer.
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsCreateInstance(Type, array<Int32>)Creates a multidimensional Array of the specified Type and dimension lengths, with zero-based indexing. The dimension lengths are specified in an array of 32-bit integers.
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibraryCreateInstance(Type, Int32)Creates a one-dimensional Array of the specified Type and length, with zero-based indexing.
Public methodStatic memberCreateInstance(Type, array<Int64>)Creates a multidimensional Array of the specified Type and dimension lengths, with zero-based indexing. The dimension lengths are specified in an array of 64-bit integers.
Public methodStatic memberSupported by Portable Class LibrarySupported in .NET for Windows Store appsCreateInstance(Type, array<Int32>, array<Int32>)Creates a multidimensional Array of the specified Type and dimension lengths, with the specified lower bounds.
Public methodStatic memberCreateInstance(Type, Int32, Int32)Creates a two-dimensional Array of the specified Type and dimension lengths, with zero-based indexing.
Public methodStatic memberCreateInstance(Type, Int32, Int32, Int32)Creates a three-dimensional Array of the specified Type and dimension lengths, with zero-based indexing.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Public methodStatic memberSupported by Portable Class LibrarySupported in .NET for Windows Store appsExists<T>Determines whether the specified array contains elements that match the conditions defined by the specified predicate.
Protected methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodStatic memberSupported by Portable Class LibrarySupported in .NET for Windows Store appsFind<T>Searches for an element that matches the conditions defined by the specified predicate, and returns the first occurrence within the entire Array.
Public methodStatic memberSupported by Portable Class LibrarySupported in .NET for Windows Store appsFindAll<T>Retrieves all the elements that match the conditions defined by the specified predicate.
Public methodStatic memberSupported by Portable Class LibrarySupported in .NET for Windows Store appsFindIndex<T>(array<T>, Predicate<T>)Searches for an element that matches the conditions defined by the specified predicate, and returns the zero-based index of the first occurrence within the entire Array.
Public methodStatic memberSupported by Portable Class LibrarySupported in .NET for Windows Store appsFindIndex<T>(array<T>, Int32, Predicate<T>)Searches for an element that matches the conditions defined by the specified predicate, and returns the zero-based index of the first occurrence within the range of elements in the Array that extends from the specified index to the last element.
Public methodStatic memberSupported by Portable Class LibrarySupported in .NET for Windows Store appsFindIndex<T>(array<T>, Int32, Int32, Predicate<T>)Searches for an element that matches the conditions defined by the specified predicate, and returns the zero-based index of the first occurrence within the range of elements in the Array that starts at the specified index and contains the specified number of elements.
Public methodStatic memberSupported by Portable Class LibrarySupported in .NET for Windows Store appsFindLast<T>Searches for an element that matches the conditions defined by the specified predicate, and returns the last occurrence within the entire Array.
Public methodStatic memberSupported by Portable Class LibrarySupported in .NET for Windows Store appsFindLastIndex<T>(array<T>, Predicate<T>)Searches for an element that matches the conditions defined by the specified predicate, and returns the zero-based index of the last occurrence within the entire Array.
Public methodStatic memberSupported by Portable Class LibrarySupported in .NET for Windows Store appsFindLastIndex<T>(array<T>, Int32, Predicate<T>)Searches for an element that matches the conditions defined by the specified predicate, and returns the zero-based index of the last occurrence within the range of elements in the Array that extends from the first element to the specified index.
Public methodStatic memberSupported by Portable Class LibrarySupported in .NET for Windows Store appsFindLastIndex<T>(array<T>, Int32, Int32, Predicate<T>)Searches for an element that matches the conditions defined by the specified predicate, and returns the zero-based index of the last occurrence within the range of elements in the Array that contains the specified number of elements and ends at the specified index.
Public methodStatic memberForEach<T>Performs the specified action on each element of the specified array.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsGetEnumeratorReturns an IEnumerator for the Array.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsGetLengthGets a 32-bit integer that represents the number of elements in the specified dimension of the Array.
Public methodGetLongLengthGets a 64-bit integer that represents the number of elements in the specified dimension of the Array.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsGetLowerBoundGets the index of the first element of the specified dimension in the array.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsGetUpperBoundGets the index of the last element of the specified dimension in the array.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsGetValue(array<Int32>)Gets the value at the specified position in the multidimensional Array. The indexes are specified as an array of 32-bit integers.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibraryGetValue(Int32)Gets the value at the specified position in the one-dimensional Array. The index is specified as a 32-bit integer.
Public methodGetValue(Int64)Gets the value at the specified position in the one-dimensional Array. The index is specified as a 64-bit integer.
Public methodGetValue(array<Int64>)Gets the value at the specified position in the multidimensional Array. The indexes are specified as an array of 64-bit integers.
Public methodGetValue(Int32, Int32)Gets the value at the specified position in the two-dimensional Array. The indexes are specified as 32-bit integers.
Public methodGetValue(Int64, Int64)Gets the value at the specified position in the two-dimensional Array. The indexes are specified as 64-bit integers.
Public methodGetValue(Int32, Int32, Int32)Gets the value at the specified position in the three-dimensional Array. The indexes are specified as 32-bit integers.
Public methodGetValue(Int64, Int64, Int64)Gets the value at the specified position in the three-dimensional Array. The indexes are specified as 64-bit integers.
Public methodStatic memberSupported by Portable Class LibrarySupported in .NET for Windows Store appsIndexOf(Array, Object)Searches for the specified object and returns the index of its first occurrence in a one-dimensional array.
Public methodStatic memberSupported by Portable Class LibrarySupported in .NET for Windows Store appsIndexOf(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.
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsIndexOf(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.
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsIndexOf<T>(array<T>, T)Searches for the specified object and returns the index of its first occurrence in a one-dimensional array.
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsIndexOf<T>(array<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.
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsIndexOf<T>(array<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.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsInitializeInitializes every element of the value-type Array by calling the default constructor of the value type.
Public methodStatic memberSupported by Portable Class LibrarySupported in .NET for Windows Store appsLastIndexOf(Array, Object)Searches for the specified object and returns the index of the last occurrence within the entire one-dimensional Array.
Public methodStatic memberSupported by Portable Class LibrarySupported in .NET for Windows Store appsLastIndexOf(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.
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsLastIndexOf(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.
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsLastIndexOf<T>(array<T>, T)Searches for the specified object and returns the index of the last occurrence within the entire Array.
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsLastIndexOf<T>(array<T>, T, Int32)Searches for the specified object and returns the index of the last occurrence within the range of elements in the Array that extends from the first element to the specified index.
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsLastIndexOf<T>(array<T>, T, Int32, Int32)Searches for the specified object and returns the index of the last occurrence within the range of elements in the Array that contains the specified number of elements and ends at the specified index.
Protected methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsResize<T>Changes the number of elements of a one-dimensional array to the specified new size.
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsReverse(Array)Reverses the sequence of the elements in the entire one-dimensional Array.
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsReverse(Array, Int32, Int32)Reverses the sequence of the elements in a range of elements in the one-dimensional Array.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsSetValue(Object, array<Int32>)Sets a value to the element at the specified position in the multidimensional Array. The indexes are specified as an array of 32-bit integers.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySetValue(Object, Int32)Sets a value to the element at the specified position in the one-dimensional Array. The index is specified as a 32-bit integer.
Public methodSetValue(Object, Int64)Sets a value to the element at the specified position in the one-dimensional Array. The index is specified as a 64-bit integer.
Public methodSetValue(Object, array<Int64>)Sets a value to the element at the specified position in the multidimensional Array. The indexes are specified as an array of 64-bit integers.
Public methodSetValue(Object, Int32, Int32)Sets a value to the element at the specified position in the two-dimensional Array. The indexes are specified as 32-bit integers.
Public methodSetValue(Object, Int64, Int64)Sets a value to the element at the specified position in the two-dimensional Array. The indexes are specified as 64-bit integers.
Public methodSetValue(Object, Int32, Int32, Int32)Sets a value to the element at the specified position in the three-dimensional Array. The indexes are specified as 32-bit integers.
Public methodSetValue(Object, Int64, Int64, Int64)Sets a value to the element at the specified position in the three-dimensional Array. The indexes are specified as 64-bit integers.
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsSort(Array)Sorts the elements in an entire one-dimensional Array using the IComparable implementation of each element of the Array.
Public methodStatic memberSort(Array, Array)Sorts a pair of one-dimensional Array objects (one contains the keys and the other contains the corresponding items) based on the keys in the first Array using the IComparable implementation of each key.
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsSort(Array, IComparer)Sorts the elements in a one-dimensional Array using the specified IComparer.
Public methodStatic memberSupported by the XNA FrameworkSort(Array, Array, IComparer)Sorts a pair of one-dimensional Array objects (one contains the keys and the other contains the corresponding items) based on the keys in the first Array using the specified IComparer.
Public methodStatic memberSupported by Portable Class LibrarySupported in .NET for Windows Store appsSort(Array, Int32, Int32)Sorts the elements in a range of elements in a one-dimensional Array using the IComparable implementation of each element of the Array.
Public methodStatic memberSort(Array, Array, Int32, Int32)Sorts a range of elements in a pair of one-dimensional Array objects (one contains the keys and the other contains the corresponding items) based on the keys in the first Array using the IComparable implementation of each key.
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsSort(Array, Int32, Int32, IComparer)Sorts the elements in a range of elements in a one-dimensional Array using the specified IComparer.
Public methodStatic memberSupported by the XNA FrameworkSort(Array, Array, Int32, Int32, IComparer)Sorts a range of elements in a pair of one-dimensional Array objects (one contains the keys and the other contains the corresponding items) based on the keys in the first Array using the specified IComparer.
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsSort<T>(array<T>)Sorts the elements in an entire Array using the IComparable<T> generic interface implementation of each element of the Array.
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsSort<T>(array<T>, IComparer<T>)Sorts the elements in an Array using the specified IComparer<T> generic interface.
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsSort<T>(array<T>, Comparison<T>)Sorts the elements in an Array using the specified Comparison<T>.
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsSort<T>(array<T>, Int32, Int32)Sorts the elements in a range of elements in an Array using the IComparable<T> generic interface implementation of each element of the Array.
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsSort<T>(array<T>, Int32, Int32, IComparer<T>)Sorts the elements in a range of elements in an Array using the specified IComparer<T> generic interface.
Public methodStatic memberSupported by the XNA FrameworkSort<TKey, TValue>(array<TKey>, array<TValue>)Sorts a pair of Array objects (one contains the keys and the other contains the corresponding items) based on the keys in the first Array using the IComparable<T> generic interface implementation of each key.
Public methodStatic memberSupported by the XNA FrameworkSort<TKey, TValue>(array<TKey>, array<TValue>, IComparer<TKey>)Sorts a pair of Array objects (one contains the keys and the other contains the corresponding items) based on the keys in the first Array using the specified IComparer<T> generic interface.
Public methodStatic memberSupported by the XNA FrameworkSort<TKey, TValue>(array<TKey>, array<TValue>, Int32, Int32)Sorts a range of elements in a pair of Array objects (one contains the keys and the other contains the corresponding items) based on the keys in the first Array using the IComparable<T> generic interface implementation of each key.
Public methodStatic memberSupported by the XNA FrameworkSort<TKey, TValue>(array<TKey>, array<TValue>, Int32, Int32, IComparer<TKey>)Sorts a range of elements in a pair of Array objects (one contains the keys and the other contains the corresponding items) based on the keys in the first Array using the specified IComparer<T> generic interface.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsToStringReturns a string that represents the current object. (Inherited from Object.)
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsTrueForAll<T>Determines whether every element in the array matches the conditions defined by the specified predicate.
Top

  NameDescription
Public Extension MethodSupported by Portable Class LibrarySupported in .NET for Windows Store appsAsParallel()Overloaded. Enables parallelization of a query. (Defined by ParallelEnumerable.)
Public Extension MethodSupported by Portable Class LibrarySupported in .NET for Windows Store appsAsParallel()Overloaded. (Defined by ParallelEnumerable.)
Public Extension MethodSupported by Portable Class LibrarySupported in .NET for Windows Store appsAsQueryable()Overloaded. Converts an IEnumerable to an IQueryable. (Defined by Queryable.)
Public Extension MethodSupported by Portable Class LibrarySupported in .NET for Windows Store appsAsQueryable()Overloaded. (Defined by Queryable.)
Public Extension MethodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsCast<TResult>()Overloaded. Casts the elements of an IEnumerable to the specified type. (Defined by Enumerable.)
Public Extension MethodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsCast<TResult>()Overloaded. (Defined by Enumerable.)
Public Extension MethodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsOfType<TResult>()Overloaded. Filters the elements of an IEnumerable based on a specified type. (Defined by Enumerable.)
Public Extension MethodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsOfType<TResult>()Overloaded. (Defined by Enumerable.)
Top

  NameDescription
Explicit interface implemetationPrivate propertySupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsICollection::CountGets the number of elements contained in the Array.
Explicit interface implemetationPrivate propertySupported by Portable Class LibrarySupported in .NET for Windows Store appsICollection::IsSynchronizedGets a value that indicates whether access to the Array is synchronized (thread safe).
Explicit interface implemetationPrivate propertySupported by Portable Class LibrarySupported in .NET for Windows Store appsICollection::SyncRootGets an object that can be used to synchronize access to the Array.
Explicit interface implemetationPrivate methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsIList::AddCalling this method always throws a NotSupportedException exception.
Explicit interface implemetationPrivate methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsIList::ClearRemoves all items from the IList.
Explicit interface implemetationPrivate methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsIList::ContainsDetermines whether an element is in the IList.
Explicit interface implemetationPrivate methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsIList::IndexOfDetermines the index of a specific item in the IList.
Explicit interface implemetationPrivate methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsIList::InsertInserts an item to the IList at the specified index.
Explicit interface implemetationPrivate propertySupported by Portable Class LibrarySupported in .NET for Windows Store appsIList::IsFixedSizeGets a value that indicates whether the Array has a fixed size.
Explicit interface implemetationPrivate propertySupported by Portable Class LibrarySupported in .NET for Windows Store appsIList::IsReadOnlyGets a value that indicates whether the Array is read-only.
Explicit interface implemetationPrivate propertySupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsIList::ItemGets or sets the element at the specified index.
Explicit interface implemetationPrivate methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsIList::RemoveRemoves the first occurrence of a specific object from the IList.
Explicit interface implemetationPrivate methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsIList::RemoveAtRemoves the IList item at the specified index.
Explicit interface implemetationPrivate methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsIStructuralComparable::CompareToDetermines whether the current collection object precedes, occurs in the same position as, or follows another object in the sort order.
Explicit interface implemetationPrivate methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsIStructuralEquatable::EqualsDetermines whether an object is equal to the current instance.
Explicit interface implemetationPrivate methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsIStructuralEquatable::GetHashCodeReturns a hash code for the current instance.
Top

NoteNote

To view the .NET Framework source code for this type, see the Reference Source. You can browse through the source code online, download the reference for offline viewing, and step through the sources (including patches and updates) during debugging; see instructions.

The Array class is not part of the System.Collections namespaces. However, it is still considered a collection because it is based on the IList interface.

The Array class is the base class for language implementations that support arrays. However, only the system and compilers can derive explicitly from the Array class. Users should employ the array constructs provided by the language.

An element is a value in an Array. The length of an Array is the total number of elements it can contain. The lower bound of an Array is the index of its first element. An Array can have any lower bound, but it has a lower bound of zero by default. A different lower bound can be defined when creating an instance of the Array class using CreateInstance. A multidimensional Array can have different bounds for each dimension. An array can have a maximum of 32 dimensions.

Unlike the classes in the System.Collections namespaces, Array has a fixed capacity. To increase the capacity, you must create a new Array object with the required capacity, copy the elements from the old Array object to the new one, and delete the old Array.

By default, the maximum size of an Array is 2 gigabytes (GB). In a 64-bit environment, you can avoid the size restriction by setting the enabled attribute of the gcAllowVeryLargeObjects configuration element to true in the run-time environment. However, the array will still be limited to a total of 4 billion elements, and to a maximum index of 0X7FEFFFFF in any given dimension (0X7FFFFFC7 for byte arrays and arrays of single-byte structures).

Starting with the .NET Framework 2.0, the Array class implements the System.Collections.Generic::IList<T>, System.Collections.Generic::ICollection<T>, and System.Collections.Generic::IEnumerable<T> generic interfaces. The implementations are provided to arrays at run time, and as a result, the generic interfaces do not appear in the declaration syntax for the Array class. In addition, there are no reference topics for interface members that are accessible only by casting an array to the generic interface type (explicit interface implementations). The key thing to be aware of when you cast an array to one of these interfaces is that members which add, insert, or remove elements throw NotSupportedException.

Type objects provide information about array type declarations. Array objects with the same array type share the same Type object.

Type::IsArray and Type::GetElementType might not return the expected results with Array because if an array is cast to the type Array, the result is an object, not an array. That is, typeof(System.Array).IsArray returns false, and typeof(System.Array).GetElementType returns nullptr.

The Array::Copy method copies elements not only between arrays of the same type but also between standard arrays of different types; it handles type casting automatically.

Some methods, such as CreateInstance, Copy, CopyTo, GetValue, and SetValue, provide overloads that accept 64-bit integers as parameters to accommodate large capacity arrays. LongLength and GetLongLength return 64-bit integers indicating the length of the array.

The Array is not guaranteed to be sorted. You must sort the Array prior to performing operations (such as BinarySearch) that require the Array to be sorted.

Using an Array object of pointers in native code is not supported and will throw a NotSupportedException for several methods.

The following code example shows how Array::Copy copies elements between an array of type integer and an array of type Object.

using namespace System;
void main1();
void main2();
void main()
{
   main1();
   Console::WriteLine();
   main2();
}

void PrintValues( array<Object^>^myArr );
void PrintValues( array<int>^myArr );
void main1()
{
   // Creates and initializes a new int array and a new Object array. 
   array<int>^myIntArray = {1,2,3,4,5};
   array<Object^>^myObjArray = {26,27,28,29,30};

   // Prints the initial values of both arrays.
   Console::WriteLine(  "Initially," );
   Console::Write(  "int array:   " );
   PrintValues( myIntArray );
   Console::Write(  "Object array:" );
   PrintValues( myObjArray );

   // Copies the first two elements from the int array to the Object array.
   System::Array::Copy( myIntArray, myObjArray, 2 );

   // Prints the values of the modified arrays.
   Console::WriteLine(  "\nAfter copying the first two elements of the int array to the Object array," );
   Console::Write(  "int array:   " );
   PrintValues( myIntArray );
   Console::Write(  "Object array:" );
   PrintValues( myObjArray );

   // Copies the last two elements from the Object array to the int array.
   System::Array::Copy( myObjArray, myObjArray->GetUpperBound( 0 ) - 1, myIntArray, myIntArray->GetUpperBound( 0 ) - 1, 2 );

   // Prints the values of the modified arrays.
   Console::WriteLine(  "\nAfter copying the last two elements of the Object array to the int array," );
   Console::Write(  "int array:   " );
   PrintValues( myIntArray );
   Console::Write(  "Object array:" );
   PrintValues( myObjArray );
}

void PrintValues( array<Object^>^myArr )
{
   for ( int i = 0; i < myArr->Length; i++ )
   {
      Console::Write(  "\t{0}", myArr[ i ] );

   }
   Console::WriteLine();
}

void PrintValues( array<int>^myArr )
{
   for ( int i = 0; i < myArr->Length; i++ )
   {
      Console::Write(  "\t{0}", myArr[ i ] );

   }
   Console::WriteLine();
}


/* 
 This code produces the following output.

 Initially,
 int array:       1    2    3    4    5
 Object array:    26    27    28    29    30
 After copying the first two elements of the int array to the Object array,
 int array:       1    2    3    4    5
 Object array:    1    2    28    29    30
 After copying the last two elements of the Object array to the int array,
 int array:       1    2    3    29    30
 Object array:    1    2    28    29    30
 */

The following code example creates and initializes an Array and displays its properties and its elements.

void PrintValues( Array^ myArr );
void main2()
{
   // Creates and initializes a new three-dimensional Array instance of type Int32.
   Array^ myArr = Array::CreateInstance( Int32::typeid, 2, 3, 4 );
   for ( int i = myArr->GetLowerBound( 0 ); i <= myArr->GetUpperBound( 0 ); i++ )
   {
      for ( int j = myArr->GetLowerBound( 1 ); j <= myArr->GetUpperBound( 1 ); j++ )
      {
         for ( int k = myArr->GetLowerBound( 2 ); k <= myArr->GetUpperBound( 2 ); k++ )
            myArr->SetValue( (i * 100) + (j * 10) + k, i, j, k );

      }
   }

   // Displays the properties of the Array.
   Console::WriteLine(  "The Array instance has {0} dimension(s) and a total of {1} elements.", myArr->Rank, myArr->Length );
   Console::WriteLine(  "\tLength\tLower\tUpper" );
   for ( int i = 0; i < myArr->Rank; i++ )
   {
      Console::Write(  "{0}:\t{1}", i, myArr->GetLength( i ) );
      Console::WriteLine(  "\t{0}\t{1}", myArr->GetLowerBound( i ), myArr->GetUpperBound( i ) );

   }
   Console::WriteLine(  "The Array instance contains the following values:" );
   PrintValues( myArr );
}

void PrintValues( Array^ myArr )
{
   System::Collections::IEnumerator^ myEnumerator = myArr->GetEnumerator();
   int i = 0;
   int cols = myArr->GetLength( myArr->Rank - 1 );
   while ( myEnumerator->MoveNext() )
   {
      if ( i < cols )
            i++;
      else
      {
         Console::WriteLine();
         i = 1;
      }

      Console::Write(  "\t{0}", myEnumerator->Current );
   }

   Console::WriteLine();
}

/* 
 This code produces the following output.

 The Array instance has 3 dimension(s) and a total of 24 elements.
     Length    Lower    Upper
 0:    2    0    1
 1:    3    0    2
 2:    4    0    3
 The Array instance contains the following values:
     0    1    2    3
     10    11    12    13
     20    21    22    23
     100    101    102    103
     110    111    112    113
     120    121    122    123
 */

.NET Framework

Supported in: 4.5.3, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

Supported in: Windows Phone 8.1

Supported in: Windows Phone Silverlight 8.1

Supported in: Windows Phone Silverlight 8

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

This implementation does not provide a synchronized (thread safe) wrapper for an Array; however, .NET Framework classes based on Array provide their own synchronized version of the collection using the SyncRoot property.

Enumerating through a collection is intrinsically not a thread-safe procedure. Even when a collection is synchronized, other threads can still modify the collection, which causes the enumerator to throw an exception. To guarantee thread safety during enumeration, you can either lock the collection during the entire enumeration or catch the exceptions resulting from changes made by other threads.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft