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
Count
Gets the number of elements actually contained in the ArrayList.
public virtual int Count { get; }
Property Value
IsFixedSize
Gets a value indicating whether the ArrayList has a fixed size.
public virtual bool IsFixedSize { get; }
Property Value
IsReadOnly
Gets a value indicating whether the ArrayList is read-only.
public virtual bool IsReadOnly { get; }
Property Value
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
indexintThe zero-based index of the element to get or set.
Property Value
SyncRoot
Gets an object that can be used to synchronize access to the ArrayList.
public virtual object SyncRoot { get; }
Property Value
Methods
Add(object)
Adds an object to the end of the ArrayList.
public virtual int Add(object value)
Parameters
valueobject
Returns
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
valueobjectThe Object to locate. The value can be null reference (Nothing in Visual Basic).
comparerIComparerThe 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
Contains(object)
Determines whether an element is in the ArrayList.
public virtual bool Contains(object value)
Parameters
valueobject
Returns
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
arrayArrayThe 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
arrayArrayThe one-dimensional Array that is the destination of the elements copied from ArrayList. The Array must have zero-based indexing.
indexintThe 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
valueobjectThe 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
valueobjectThe Object to locate in the ArrayList. The value can be null reference (Nothing in Visual Basic).
startIndexintThe 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
valueobjectThe Object to locate in the ArrayList. The value can be null reference (Nothing in Visual Basic).
startIndexintThe zero-based starting index of the search. 0 (zero) is valid in an empty list.
countintThe 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
Remove(object)
Removes the first occurrence of a specific object from the ArrayList.
public virtual void Remove(object value)
Parameters
RemoveAt(int)
Removes the element at the specified index of the ArrayList.
public virtual void RemoveAt(int index)
Parameters
indexintThe zero-based index of the element to remove.
ToArray()
public virtual object[] ToArray()
Returns
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
typeTypeThe element Type of the destination array to create and copy elements to.