Table of Contents

Class ArrayList

Namespace
System.Collections
Assembly
mscorlib.dll

Implements the IList interface using an array whose size is dynamically increased as required.

public class ArrayList : IList, ICollection, IEnumerable, ICloneable
Inheritance
ArrayList
Implements
Inherited Members
Extension Methods

Constructors

ArrayList()

Initializes a new instance of the ArrayList class that is empty and has the default initial capacity.

public ArrayList()

Properties

Capacity

Gets or sets the number of elements that the ArrayList can contain.

public virtual int Capacity { get; set; }

Property Value

int

The number of elements that the ArrayList can contain.

Count

Gets the number of elements actually contained in the ArrayList.

public virtual int Count { get; }

Property Value

int

The number of elements actually contained in the ArrayList.

IsFixedSize

Gets a value indicating whether the ArrayList has a fixed size.

public virtual bool IsFixedSize { get; }

Property Value

bool

true if the ArrayList has a fixed size; otherwise, false. The default is false.

IsReadOnly

Gets a value indicating whether the ArrayList is read-only.

public virtual bool IsReadOnly { get; }

Property Value

bool

true if the ArrayList is read-only; otherwise, false. The default is false.

IsSynchronized

Gets a value indicating whether access to the ArrayList is synchronized (thread safe).

public virtual bool IsSynchronized { get; }

Property Value

bool

true if access to the ArrayList is synchronized (thread safe); otherwise, false. The default is false.

this[int]

Gets or sets the element at the specified index.

public virtual object this[int index] { get; set; }

Parameters

index int

The zero-based index of the element to get or set.

Property Value

object

SyncRoot

Gets an object that can be used to synchronize access to the ArrayList.

public virtual object SyncRoot { get; }

Property Value

object

An object that can be used to synchronize access to the ArrayList.

Methods

Add(object)

Adds an object to the end of the ArrayList.

public virtual int Add(object value)

Parameters

value object

Returns

int

The object to be added to the end of the ArrayList. The value can be null.

BinarySearch(object, IComparer)

Searches the entire sorted ArrayList for an element using the specified comparer and returns the zero-based index of the element.

public virtual int BinarySearch(object value, IComparer comparer)

Parameters

value object

The Object to locate. The value can be null reference (Nothing in Visual Basic).

comparer IComparer

The IComparer implementation to use when comparing elements.

-or-

nullNothingnullptrunit a null reference(Nothing in Visual Basic) to use the IComparable implementation of each element.

Returns

int

The zero-based index of value in the sorted ArrayList, if value is found; otherwise, a negative number, which is the bitwise complement of the index of the next element that is larger than value or, if there is no larger element, the bitwise complement of Count.

Clear()

Removes all elements from the ArrayList.

public virtual void Clear()

Clone()

Creates a shallow copy of the ArrayList.

public virtual object Clone()

Returns

object

A shallow copy of the ArrayList.

Contains(object)

Determines whether an element is in the ArrayList.

public virtual bool Contains(object value)

Parameters

value object

Returns

bool

Theobject to locate in the ArrayList.The value can be null.

CopyTo(Array)

Copies the entire ArrayList to a compatible one-dimensional Array, starting at the beginning of the target array.

public virtual void CopyTo(Array array)

Parameters

array Array

The one-dimensional Array that is the destination of the elements copied from ArrayList. The Array must have zero-based indexing.

CopyTo(Array, int)

Copies the entire ArrayList to a compatible one-dimensional Array, starting at the specified index of the target array.

public virtual void CopyTo(Array array, int index)

Parameters

array Array

The one-dimensional Array that is the destination of the elements copied from ArrayList. The Array must have zero-based indexing.

index int

The zero-based index in array at which copying begins.

GetEnumerator()

Returns an enumerator for the entire ArrayList.

public virtual IEnumerator GetEnumerator()

Returns

IEnumerator

An IEnumerator for the entire ArrayList.

IndexOf(object)

Searches for the specified Object and returns the zero-based index of the first occurrence within the entire ArrayList.

public virtual int IndexOf(object value)

Parameters

value object

The Object to locate in the ArrayList. The value can be null reference (Nothing in Visual Basic).

Returns

int

The zero-based index of the first occurrence of value within the entire ArrayList, if found; otherwise, -1.

IndexOf(object, int)

Searches for the specified Object and returns the zero-based index of the first occurrence within the range of elements in the ArrayList that extends from the specified index to the last element.

public virtual int IndexOf(object value, int startIndex)

Parameters

value object

The Object to locate in the ArrayList. The value can be null reference (Nothing in Visual Basic).

startIndex int

The zero-based starting index of the search. 0 (zero) is valid in an empty list.

Returns

int

The zero-based index of the first occurrence of value within the range of elements in the ArrayList that extends from startIndex to the last element, if found; otherwise, -1.

IndexOf(object, int, int)

Searches for the specified Object and returns the zero-based index of the first occurrence within the range of elements in the ArrayList that starts at the specified index and contains the specified number of elements.

public virtual int IndexOf(object value, int startIndex, int count)

Parameters

value object

The Object to locate in the ArrayList. The value can be null reference (Nothing in Visual Basic).

startIndex int

The zero-based starting index of the search. 0 (zero) is valid in an empty list.

count int

The number of elements in the section to search.

Returns

int

The zero-based index of the first occurrence of value within the range of elements in the ArrayList that starts at startIndex and contains count number of elements, if found; otherwise, -1.

Insert(int, object)

Inserts an element into the ArrayList at the specified index.

public virtual void Insert(int index, object value)

Parameters

index int

The zero-based index at which

value

should be inserted.
value object

The object to insert. The value can be null.

Remove(object)

Removes the first occurrence of a specific object from the ArrayList.

public virtual void Remove(object value)

Parameters

value object

The object to remove from the ArrayList. The value can be null.

RemoveAt(int)

Removes the element at the specified index of the ArrayList.

public virtual void RemoveAt(int index)

Parameters

index int

The zero-based index of the element to remove.

ToArray()

Copies the elements of the ArrayList to a new object array.

public virtual object[] ToArray()

Returns

object[]

An Object array containing copies of the elements of the ArrayList.

Remarks

Available only in mscorlib build with support for System.Reflection.

ToArray(Type)

Copies the elements of the ArrayList to a new array of the specified element type.

public virtual Array ToArray(Type type)

Parameters

type Type

The element Type of the destination array to create and copy elements to.

Returns

Array

An array of the specified element type containing copies of the elements of the ArrayList.

get_Item(int)

public virtual object get_Item(int index)

Parameters

index int

Returns

object

set_Item(int, object)

public virtual void set_Item(int index, object value)

Parameters

index int
value object