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 | |
---|---|---|
Array | Initializes a new instance of the Array class. |
Top
Properties
Name | Description | |
---|---|---|
IsFixedSize | Gets a value indicating whether the Array has a fixed size. | |
IsReadOnly | Gets a value indicating whether the Array is read-only. | |
IsSynchronized | Gets a value indicating whether access to the Array is synchronized (thread safe). | |
Length | Gets a 32-bit integer that represents the total number of elements in all the dimensions of the Array. | |
SyncRoot | Gets an object that can be used to synchronize access to the Array. |
Top
Methods
Name | Description | |
---|---|---|
BinarySearch(Array, Object, IComparer) | Searches an entire one-dimensional sorted Array for a value using the specified IComparer interface. | |
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. | |
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. | |
Clone | Creates a shallow copy of the Array. | |
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. | |
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. | |
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. | |
CreateInstance | Creates a one-dimensional Array of the specified Type and length, with zero-based indexing. | |
Equals(Object) | Determines whether the specified Object is equal to the current Object. (Inherited from Object.) | |
Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) | |
GetEnumerator | Returns an IEnumerator for the Array. | |
GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) | |
GetType | Gets the Type of the current instance. (Inherited from Object.) | |
GetValue | Gets the value at the specified position in the one-dimensional Array. The index is specified as a 32-bit integer. | |
IndexOf(Array, Object) | Searches for the specified object and returns the index of the first occurrence within the entire one-dimensional Array. | |
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. | |
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. | |
MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) | |
ToString | Returns a string that represents the current object. (Inherited from Object.) |
Top
Explicit Interface Implementations
Name | Description | |
---|---|---|
ICollection. . :: . .Count | Gets the number of elements contained in the Array. | |
IList. . :: . .Add | Adds an item to IList. | |
IList. . :: . .Clear | Removes all items from the IList. | |
IList. . :: . .Contains | Determines whether an element is in the IList. | |
IList. . :: . .IndexOf | Determines the index of a specific item in the IList. | |
IList. . :: . .Insert | Inserts an item to the IList at the specified index. | |
IList. . :: . .Item | Gets or sets the element at the specified index. | |
IList. . :: . .Remove | Removes the first occurrence of a specific object from the IList. | |
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.