Share via


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.

Inheritance Hierarchy

System. . :: . .Object
  System..::..Array

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

Syntax

'Declaration
<SerializableAttribute> _
Public MustInherit Class Array _
    Implements ICloneable, IList, ICollection, IEnumerable
[SerializableAttribute]
public abstract class Array : ICloneable, 
    IList, ICollection, IEnumerable
[SerializableAttribute]
public ref class Array abstract : ICloneable, 
    IList, ICollection, IEnumerable
[<AbstractClass>]
[<SerializableAttribute>]
type Array =  
    class
        interface ICloneable
        interface IList
        interface ICollection
        interface IEnumerable
    end
public abstract class Array implements ICloneable, IList, ICollection, IEnumerable

The Array type exposes the following members.

Constructors

  Name Description
Protected method Array Initializes a new instance of the Array class.

Top

Properties

  Name Description
Public property IsFixedSize Gets a value indicating whether the Array has a fixed size.
Public property IsReadOnly Gets a value indicating whether the Array is read-only.
Public property IsSynchronized Gets a value indicating whether access to the Array is synchronized (thread safe).
Public property Length Gets a 32-bit integer that represents the total number of elements in all the dimensions of the Array.
Public property SyncRoot Gets an object that can be used to synchronize access to the Array.

Top

Methods

  Name Description
Public methodStatic member BinarySearch(Array, Object, IComparer) Searches an entire one-dimensional sorted Array for a value using the specified IComparer interface.
Public methodStatic member BinarySearch(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 member Clear Sets 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 method Clone Creates a shallow copy of the Array.
Public methodStatic member 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.
Public methodStatic member 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.
Public method CopyTo 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 methodStatic member CreateInstance Creates a one-dimensional Array of the specified Type and length, with zero-based indexing.
Public method Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method GetEnumerator Returns an IEnumerator for the Array.
Public method GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Public method GetValue Gets the value at the specified position in the one-dimensional Array. The index is specified as a 32-bit integer.
Public methodStatic member IndexOf(Array, Object) Searches for the specified object and returns the index of the first occurrence within the entire one-dimensional Array.
Public methodStatic member 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.
Public methodStatic member 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.
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public method ToString Returns a string that represents the current object. (Inherited from Object.)

Top

Explicit Interface Implementations

  Name Description
Explicit interface implemetationPrivate property ICollection. . :: . .Count Gets the number of elements contained in the Array.
Explicit interface implemetationPrivate method IList. . :: . .Add Adds an item to IList.
Explicit interface implemetationPrivate method IList. . :: . .Clear Removes all items from the IList.
Explicit interface implemetationPrivate method IList. . :: . .Contains Determines whether an element is in the IList.
Explicit interface implemetationPrivate method IList. . :: . .IndexOf Determines the index of a specific item in the IList.
Explicit interface implemetationPrivate method IList. . :: . .Insert Inserts an item to the IList at the specified index.
Explicit interface implemetationPrivate property IList. . :: . .Item Gets or sets the element at the specified index.
Explicit interface implemetationPrivate method IList. . :: . .Remove Removes the first occurrence of a specific object from the IList.
Explicit interface implemetationPrivate method IList. . :: . .RemoveAt Removes the IList item at the specified index.

Top

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.

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 Nothing nullptr unit a 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.

Thread Safety

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.

See Also

Reference

System Namespace