ArrayList Class
Constructors
-
ArrayList()
public ArrayList()Initializes a new instance of the ArrayList class that is empty and has the initial capacity of zero or the default capacity if that is greater.
-
ArrayList(int capacity)
public ArrayList(int capacity)Initializes a new instance of the ArrayList class that is empty and has the specified initial capacity or the default capacity if that is greater.
Parameters:capacity
— The number of elements that the new ArrayList can initially store. -
ArrayList(IList c)
public ArrayList(IList c)Initializes a new instance of the ArrayList class that contains elements copied from the specified collection and has enough capacity to accommodate the number of elements copied.
Parameters:c
— The collection whose elements are copied to the new ArrayList.
Properties
-
Capacity
public virtual int Capacity { get; set; }Gets or sets the number of elements that the ArrayList can hold.
Inherited from: ArrayList -
Count
public virtual int Count { get; }Gets the number of elements contained in the ArrayList.
Inherited from: ArrayList -
IsFixedSize
public virtual bool IsFixedSize { get; }Gets a value indicating whether the ArrayList has a fixed size.
Inherited from: IList -
IsReadOnly
public virtual bool IsReadOnly { get; }Gets a value indicating whether the ArrayList is read-only.
Inherited from: IList -
IsSynchronized
public virtual bool IsSynchronized { get; }Gets a value indicating whether access to the ArrayList is synchronized (thread-safe).
Inherited from: ArrayList -
Item[int index]
public virtual object Item[int index] { get; set; }Gets or sets the element at the specified index.
Parameters:index
— The zero-based index of the element to get or set.Inherited from: IList -
SyncRoot
public virtual object SyncRoot { get; }Gets an object that can be used to synchronize access to the ArrayList.
Inherited from: ArrayList
Methods
-
Add(object value)
public virtual int Add(object value)Adds an object to the end of the ArrayList.
Parameters:value
— The object to be added to the end of the ArrayList.Returns: The position into which the new element is inserted.Inherited from: IList -
AddRange(ICollection c)
public virtual void AddRange(ICollection c)Adds the elements of the specified collection to the end of the ArrayList.
Parameters:c
— The collection whose elements are to be added to the end of the ArrayList.Inherited from: ArrayList -
Clear()
public virtual void Clear()Removes all elements from the ArrayList.
Inherited from: ArrayList -
Clone()
public virtual object Clone()Creates a shallow copy of the ArrayList.
Returns: A shallow copy of the ArrayList.Inherited from: ArrayList -
Contains(object value)
public virtual bool Contains(object value)Determines whether an element is in the ArrayList.
Parameters:value
— The object to locate in the ArrayList.Returns:true
if the object is found in the ArrayList; otherwise,false
.Inherited from: ArrayList -
CopyTo(Array array)
public virtual void CopyTo(Array array)Copies the entire ArrayList to a one-dimensional Array, starting at the beginning of the target array.
Parameters:array
— The one-dimensional Array that is the destination of the elements copied from ArrayList.Inherited from: ArrayList -
GetEnumerator()
public virtual IEnumerator GetEnumerator()Returns an enumerator that iterates through the ArrayList.
Returns: An IEnumerator for the ArrayList.Inherited from: ArrayList -
IndexOf(object value)
public virtual int IndexOf(object value)Searches for the specified object and returns the zero-based index of the first occurrence within the entire ArrayList.
Parameters:value
— The object to search for.Returns: The zero-based index of the first occurrence of value within the entire ArrayList, or -1 if there is no such element.Inherited from: ArrayList -
Insert(int index, object value)
public virtual void Insert(int index, object value)Inserts an element into the ArrayList at the specified index.
Parameters:index
— The zero-based index at which value should be inserted.value
— The object to insert into the ArrayList.Inherited from: IList -
Remove(object value)
public virtual void Remove(object value)Removes the first occurrence of the specified object from the ArrayList.
Parameters:value
— The object to remove from the ArrayList.Inherited from: ArrayList -
RemoveAt(int index)
public virtual void RemoveAt(int index)Removes the element at the specified index of the ArrayList.
Parameters:index
— The zero-based index of the element to remove.Inherited from: IList -
Reverse()
public virtual void Reverse()Reverses the order of the elements in the entire ArrayList.
Inherited from: ArrayList -
Sort()
public virtual void Sort()Sorts the elements in the entire ArrayList.
Inherited from: ArrayList -
ToArray()
public virtual object[] ToArray()Copies the elements of the ArrayList to a new object array.
Returns: A new object array containing the elements of the ArrayList.Inherited from: ArrayList -
TrimToSize()
public virtual void TrimToSize()Adjusts the capacity of an ArrayList so that the capacity is equal to the number of elements in the ArrayList.
Inherited from: ArrayList