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
index
intThe 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
value
object
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
value
objectThe Object to locate. The value can be null reference (Nothing in Visual Basic).
comparer
IComparerThe 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
value
object
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
array
ArrayThe 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
ArrayThe one-dimensional Array that is the destination of the elements copied from ArrayList. The Array must have zero-based indexing.
index
intThe 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
objectThe 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
objectThe Object to locate in the ArrayList. The value can be null reference (Nothing in Visual Basic).
startIndex
intThe 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
objectThe Object to locate in the ArrayList. The value can be null reference (Nothing in Visual Basic).
startIndex
intThe zero-based starting index of the search. 0 (zero) is valid in an empty list.
count
intThe 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
index
intThe 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
type
TypeThe element Type of the destination array to create and copy elements to.
Returns
get_Item(int)
public virtual object get_Item(int index)
Parameters
index
int
Returns
set_Item(int, object)
public virtual void set_Item(int index, object value)