System.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.

See Also: Array Members

Syntax

[System.Runtime.InteropServices.ComVisible(true)]
public abstract class Array : IList, IStructuralComparable, IStructuralEquatable, ICloneable

Remarks

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 rank of an Array is the number of dimensions in the Array. The lower bound of a dimension of an Array is the starting index of that dimension of the Array; a multidimensional Array can have different bounds for each dimension. An array can have a maximum of 32 dimensions.

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).

Note:

Starting with the .NET Framework 2.0, the Array class implements the IList`1, ICollection`1, and IEnumerable`1 generic interfaces. The implementations are provided to arrays at run time, and therefore are not visible to the documentation build tools. As a result, the generic interfaces do not appear in the declaration syntax for the Array class, and 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 null.

Unlike most classes, Array provides the erload:System.Array.CreateInstance method, instead of public constructors, to allow for late bound access.

The Array.Copy(Array, Array, int) 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 Array.CreateInstance(Type, int), Array.Copy(Array, Array, int), Array.CopyTo(Array, int), erload:System.Array.GetValue, and erload:System.Array.SetValue, provide overloads that accept 64-bit integers as parameters to accommodate large capacity arrays. Array.LongLength and Array.GetLongLength(int) 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 erload:System.Array.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.

Thread Safety

All public static members of this type are safe for multithreaded operations. No instance members are guaranteed to be thread safe.

Requirements

Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0