Array Class

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

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

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

[<AbstractClass>]
[<SerializableAttribute>]
type Array =  
    class
        interface ICloneable
        interface IList
        interface ICollection
        interface IEnumerable
    end

The Array type exposes the following members.

  NameDescription
Protected methodArrayInitializes a new instance of the Array class.
Top

  NameDescription
Public propertyIsFixedSizeGets a value indicating whether the Array has a fixed size.
Public propertyIsReadOnlyGets a value indicating whether the Array is read-only.
Public propertyIsSynchronizedGets a value indicating whether access to the Array is synchronized (thread safe).
Public propertyLengthGets a 32-bit integer that represents the total number of elements in all the dimensions of the Array.
Public propertySyncRootGets an object that can be used to synchronize access to the Array.
Top

  NameDescription
Public methodStatic memberBinarySearch(Array, Object, IComparer)Searches an entire one-dimensional sorted Array for a value using the specified IComparer interface.
Public methodStatic memberBinarySearch(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 memberClearSets a range of elements in the Array to zero, to false, or to nullNothingnullptrunita null reference (Nothing in Visual Basic), depending on the element type.
Public methodCloneCreates a shallow copy of the Array.
Public methodStatic memberCopy(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, 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 methodCopyToCopies 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 methodStatic memberCreateInstanceCreates a one-dimensional Array of the specified Type and length, with zero-based indexing.
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetEnumeratorReturns an IEnumerator for the Array.
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodGetValueGets the value at the specified position in the one-dimensional Array. The index is specified as a 32-bit integer.
Public methodStatic memberIndexOf(Array, Object)Searches for the specified object and returns the index of the first occurrence within the entire one-dimensional Array.
Public methodStatic memberIndexOf(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.
Public methodStatic memberIndexOf(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.
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

  NameDescription
Explicit interface implemetationPrivate propertyICollection..::..CountGets the number of elements contained in the Array.
Explicit interface implemetationPrivate methodIList..::..AddAdds an item to IList.
Explicit interface implemetationPrivate methodIList..::..ClearRemoves all items from the IList.
Explicit interface implemetationPrivate methodIList..::..ContainsDetermines whether an element is in the IList.
Explicit interface implemetationPrivate methodIList..::..IndexOfDetermines the index of a specific item in the IList.
Explicit interface implemetationPrivate methodIList..::..InsertInserts an item to the IList at the specified index.
Explicit interface implemetationPrivate propertyIList..::..ItemGets or sets the element at the specified index.
Explicit interface implemetationPrivate methodIList..::..RemoveRemoves the first occurrence of a specific object from the IList.
Explicit interface implemetationPrivate methodIList..::..RemoveAtRemoves the IList item at the specified index.
Top

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.

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 nullNothingnullptrunita null reference (Nothing in Visual Basic).

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

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.

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.

Show: