public class ArrayList : ICloneable, ICollection, IEnumerable, IList
Object
ArrayListThis type implements IList, ICollection, IEnumerable, and ICloneable.
mscorlib
BCL
Implements a variable-size IList that uses an array of objects to store its elements.
ArrayList implements a variable-size IList that uses an array of objects to store the elements. A ArrayList has a System.Collections.ArrayList.Capacity, which is the allocated length of the internal array. The total number of elements contained by a list is its System.Collections.ArrayList.Count. As elements are added to a list, its capacity is automatically increased as required by reallocating the internal array.
The following example shows how to create, initialize, and display the values of a ArrayList.
using System; using System.Collections; public class SamplesArrayList { public static void Main() { // Create and initialize a new ArrayList. ArrayList myAL = new ArrayList(); myAL.Add("Hello"); myAL.Add("World"); myAL.Add("!"); // Display the properties and values of the ArrayList. Console.WriteLine( "myAL" ); Console.WriteLine( "Count: {0}", myAL.Count ); Console.WriteLine( "Capacity: {0}", myAL.Capacity ); Console.Write( "Values:" ); PrintValues( myAL ); } public static void PrintValues( IEnumerable myList ) { IEnumerator myEnumerator = myList.GetEnumerator(); while ( myEnumerator.MoveNext() ) Console.Write( " {0}", myEnumerator.Current ); Console.WriteLine(); } }The output is
myAL
Count: 3
Capacity: 16
Values: Hello World !
DefaultMemberAttribute("Item")
System.Collections Namespace
ArrayList Constructors
ArrayList() Constructor
ArrayList(int) Constructor
ArrayList(System.Collections.ICollection) Constructor
ArrayList Methods
ArrayList.Adapter Method
ArrayList.Add Method
ArrayList.AddRange Method
ArrayList.BinarySearch(System.Object, System.Collections.IComparer) Method
ArrayList.BinarySearch(System.Object) Method
ArrayList.BinarySearch(int, int, System.Object, System.Collections.IComparer) Method
ArrayList.Clear Method
ArrayList.Clone Method
ArrayList.Contains Method
ArrayList.CopyTo(System.Array, int) Method
ArrayList.CopyTo(int, System.Array, int, int) Method
ArrayList.CopyTo(System.Array) Method
ArrayList.FixedSize Method
ArrayList.GetEnumerator() Method
ArrayList.GetEnumerator(int, int) Method
ArrayList.GetRange Method
ArrayList.IndexOf(System.Object) Method
ArrayList.IndexOf(System.Object, int, int) Method
ArrayList.IndexOf(System.Object, int) Method
ArrayList.Insert Method
ArrayList.InsertRange Method
ArrayList.LastIndexOf(System.Object, int, int) Method
ArrayList.LastIndexOf(System.Object, int) Method
ArrayList.LastIndexOf(System.Object) Method
ArrayList.ReadOnly Method
ArrayList.Remove Method
ArrayList.RemoveAt Method
ArrayList.RemoveRange Method
ArrayList.Repeat Method
ArrayList.Reverse(int, int) Method
ArrayList.Reverse() Method
ArrayList.SetRange Method
ArrayList.Sort(int, int, System.Collections.IComparer) Method
ArrayList.Sort(System.Collections.IComparer) Method
ArrayList.Sort() Method
ArrayList.Synchronized Method
ArrayList.ToArray(System.Type) Method
ArrayList.ToArray() Method
ArrayList.TrimToSize Method
ArrayList Properties
ArrayList.Capacity Property
ArrayList.Count() Property
ArrayList.Count() Property
ArrayList.IsFixedSize() Property
ArrayList.IsFixedSize() Property
ArrayList.IsReadOnly() Property
ArrayList.IsReadOnly() Property
ArrayList.IsSynchronized() Property
ArrayList.IsSynchronized() Property
ArrayList.Item Property
ArrayList.SyncRoot() Property
ArrayList.SyncRoot() Property
public ArrayList();
Constructs and initializes a new instance of the ArrayList class that is empty and has the default initial System.Collections.ArrayList.Capacity .
The default initial System.Collections.ArrayList.Capacity of a ArrayList is 16.
System.Collections.ArrayList Class, System.Collections Namespace
public ArrayList(int capacity);
Constructs and initializes a new instance of the ArrayList class that is empty and has the specified initial System.Collections.ArrayList.Capacity .
- capacity
- A Int32 that specifies the number of elements that the new instance is initially capable of storing.
Exception Type Condition ArgumentOutOfRangeException capacity < 0.
If capacity is zero, the System.Collections.ArrayList.Capacity of the current instance is set to 16 when the first element is added.
System.Collections.ArrayList Class, System.Collections Namespace
public ArrayList(ICollection c);
Constructs and initializes a new instance of the ArrayList class with the elements from the specified ICollection. The initial System.Collections.ArrayList.Count and System.Collections.ArrayList.Capacity of the new list are both equal to the number of elements in the specified collection.
- c
- The ICollection whose elements are copied to the new list.
Exception Type Condition ArgumentNullException c is null
.
The elements in the new ArrayList instance are in the same order as contained in c.
System.Collections.ArrayList Class, System.Collections Namespace
public static ArrayList Adapter(IList list);
Creates a ArrayList that is a wrapper for the specified IList.
- list
- The IList to wrap.
The ArrayList wrapper for list.
Exception Type Condition ArgumentNullException list is null
.
This method returns a ArrayList that contains a reference to the IListlist . Any modifications to the elements in either the returned list or list are reflected in the other.[Note: The ArrayList class provides generic System.Collections.ArrayList.Reverse, System.Collections.ArrayList.BinarySearch(System.Int32,System.Int32,System.Object,System.Collections.IComparer) and System.Collections.ArrayList.Sort methods. This wrapper provides a means to use those methods on IListlist without implementing the methods for the list. Performing these operations through the wrapper may be less efficient than operations applied directly to the list.]
System.Collections.ArrayList Class, System.Collections Namespace
public virtual int Add(object value);
Adds the specified Object to the end of the current instance.
- value
- The Object to be added to the end of the current instance.
A Int32 that specifies the index of the current instance at which value has been added.
Exception Type Condition NotSupportedException The current instance is read-only or has a fixed size.
[Behaviors: As described above.]
System.Collections.ArrayList Class, System.Collections Namespace
public virtual void AddRange(ICollection c);
Adds the elements of the specified ICollection to the end of the current instance.
- c
- The ICollection whose elements are added to the end of the current instance.
Exception Type Condition ArgumentNullException c is null
.NotSupportedException The current instance is read-only or has a fixed size.
[Behaviors: As described above.]
[Default: If the System.Collections.ArrayList.Count of the current instance plus the size of the collection being added is greater than the System.Collections.ArrayList.Capacity of the current instance, the capacity of the current instance is either doubled or increased to the new System.Collections.ArrayList.Count, whichever is greater. The internal array is reallocated to accommodate the new elements and the existing elements are copied to the new array before the new elements are added.]
[Note: For the default implementation, if the current instance can accommodate the new elements without increasing the System.Collections.ArrayList.Capacity, this method is an O(n) operation, where n is the number of elements to be added. If the capacity needs to be increased to accommodate the new elements, this method becomes an O(n+m) operation, where n is the number of elements to be added and m is System.Collections.ArrayList.Count .]
System.Collections.ArrayList Class, System.Collections Namespace
public virtual int BinarySearch(object value, IComparer comparer);
Searches the current instance for the specified Object using the specified IComparer implementation.
- value
- The Object for which to search.
- comparer
- The IComparer implementation to use when comparing elements. Specify
null
to use the IComparable implementation of each element.
A Int32 that specifies the results of the search as follows:
[Note: If value is not found and the current instance is already sorted, the bitwise complement of the return value indicates the index in the current instance where value would be found.]
Return Value Description The index of value in the current instance. value was found. The bitwise complement of the index of the first element that is greater than value. value was not found, and at least one element in the current instance is greater than value. The bitwise complement of the System.Collections.ArrayList.Count of the current instance. value was not found, and value is greater than all elements in the current instance.
Exception Type Condition ArgumentException comparer is null
, and both value and at least one element in the current instance do not implement the IComparable interface.-or-
comparer is
null
, and value is not assignment-compatible with at least one element in the current instance.
[Note: A null reference can be compared with any type; therefore, comparisons with a null reference do not generate exceptions. A null reference evaluates to less than any non-null object, or equal to another null reference, when the two are compared.]
[Behaviors: As described above.]
[Default: This method uses System.Array.BinarySearch(System.Array,System.Object) to search for value.
value is compared to elements in a binary search of the current instance until an element with a value greater than or equal to value is found. If comparer is
null
, the IComparable implementation of the element being compared -- or of value if the element being compared does not implement the interface -- is used to make the comparison. If value does not implement the IComparable interface and is compared to an element that does not implement the interface either, ArgumentException is thrown. If the current instance is not already sorted, correct results are not guaranteed.]
[Note: For the default implementation, this method is an O(log2n) operation where n is equal to the System.Collections.ArrayList.Count of the current instance.]
System.Collections.ArrayList Class, System.Collections Namespace
public virtual int BinarySearch(object value);
Searches the current instance for the specified Object.
- value
- The Object for which to search.
A Int32 that specifies the results of the search as follows:
[Note: If value is not found and the current instance is already sorted, the bitwise complement of the return value indicates the index in the current instance where value would be found.]
Return Value Description The index of value in the current instance. value was found. The bitwise complement of the index of the first element that is greater than value. value was not found, and at least one element in the current instance is greater than value. The bitwise complement of the System.Collections.ArrayList.Count of the current instance. value was not found, and value is greater than all elements in the current instance.
Exception Type Condition ArgumentException Both value and at least one element of the current instance do not implement the IComparable interface. -or-
value is not assignment-compatible with at least one element in the current instance.
[Note: A null reference can be compared with any type; therefore, comparisons with a null reference do not generate exceptions. A null reference evaluates to less than any non-null object, or equal to another null reference, when the two are compared.]
[Behaviors: As described above.]
[Default: This method uses System.Array.BinarySearch(System.Array,System.Object) to search for value.
value is compared to elements in a binary search of the current instance until an element with a value greater than or equal to value is found. The IComparable implementation of the element being compared -- or of value if the element being compared does not implement the interface -- is used to make the comparison. If value does not implement the IComparable interface and is compared to an element that does not implement the interface either, ArgumentException is thrown. If the current instance is not already sorted, correct results are not guaranteed.
]
[Note: For the default implementation, this method is an O(log2n) operation where n is equal to the System.Collections.ArrayList.Count of the current instance.]
System.Collections.ArrayList Class, System.Collections Namespace
public virtual int BinarySearch(int index, int count, object value, IComparer comparer);
Searches the specified range in the current instance for the specified Object using the specified IComparer implementation.
- index
- A Int32 that specifies the index at which searching starts. This value is greater than or equal to zero, and less than the System.Collections.ArrayList.Count of the current instance.
- count
- A Int32 that specifies the number of elements to search, beginning with index . This value is greater than or equal to zero, and less than or equal to the System.Collections.ArrayList.Count of the current instance minus index.
- value
- The Object for which to search.
- comparer
- The IComparer implementation to use when comparing elements. Specify
null
to use the IComparable implementation of each element.
A Int32 that specifies the results of the search as follows:
[Note: If value is not found and the current instance is already sorted, the bitwise complement of the return value indicates the index in the current instance where value would be found in the range of index to index + count .]
Return Value Description The index of value in the current instance. value was found. The bitwise complement of the index of the first element that is greater than value. value was not found, and at least one element in the range of index to index + count in the current instance is greater than value. The bitwise complement of (index + count) value was not found, and value is greater than all elements in the range of index to index + count in the current instance.
Exception Type Condition ArgumentException System.Collections.ArrayList.Count of the current instance - index < count. -or-
comparer is
null
, and both value and at least one element of the current instance do not implement the IComparable interface.-or-
comparer is
null
, and value is not assignment-compatible with at least one element in the current instance.
ArgumentOutOfRangeException index < 0. -or-
count < 0.
[Note: A null reference can be compared with any type; therefore, comparisons with a null reference do not generate exceptions. A null reference evaluates to less than any non-null object, or equal to another null reference, when the two are compared.]
[Behaviors: As described above.]
[Default: This method uses System.Array.BinarySearch(System.Array,System.Object) to search for value .
value is compared to elements in a binary search of the range of index to index + count in the current instance until an element with a value greater than or equal to value is found or the end of the range is reached. If comparer is
null
, the IComparable implementation of the element being compared -- or of value if the element being compared does not implement the interface -- is used to make the comparison. If value does not implement the IComparable interface and is compared to an element that does not implement the interface either, ArgumentException is thrown. If the current instance is not already sorted, correct results are not guaranteed.]
[Note: For the default implementation, this method is an O(log2count) operation.]
System.Collections.ArrayList Class, System.Collections Namespace
public virtual void Clear();
Sets the elements in the current instance to zero,false
, ornull
, depending upon the element type.
Exception Type Condition NotSupportedException The current instance is read-only or has a fixed size.
[Note: This method is implemented to support the IList interface. ]
[Behaviors: Reference-type elements are set to
null
. Value-type elements are set to zero, except for Boolean elements, which are set tofalse
. ]
[Default: This method uses System.Array.Clear(System.Array,System.Int32,System.Int32) to reset the values of the current instance. System.Collections.ArrayList.Count is set to zero. System.Collections.ArrayList.Capacity is not changed. ]
[Usage: To reset the System.Collections.ArrayList.Capacity of the current instance, call System.Collections.ArrayList.TrimToSize or set the System.Collections.ArrayList.Capacity property directly. ]
System.Collections.ArrayList Class, System.Collections Namespace
public virtual object Clone();
Returns a Object that is a copy of the current instance.
A Object that is a copy of the current instance.
[Note: This method is implemented to support the ICloneable interface.]
[Behaviors: As described above.]
[Default: This method uses System.Array.Copy(System.Array,System.Array,System.Int32) to clone the current instance.]
System.Collections.ArrayList Class, System.Collections Namespace
public virtual bool Contains(object item);
Determines whether the specified Object is contained in the current instance.
- item
- The Object to locate in the current instance.
true
if item is contained in the current instance; otherwise,false
.
[Note: This method is implemented to support the IList interface.]
[Behaviors: As described above.]
[Default: This method determines equality by calling the System.Object.Equals(System.Object) implementation of the type of item.]
[Note: For the default implementation, this method is an O(n) operation where n is equal to the System.Collections.ArrayList.Count of the current instance. If the current instance is sorted, it is more efficient to call System.Collections.ArrayList.BinarySearch(System.Int32,System.Int32,System.Object,System.Collections.IComparer) method.]
System.Collections.ArrayList Class, System.Collections Namespace
public virtual void CopyTo(Array array, int arrayIndex);
Copies the elements from the current instance to the specified Array , starting at the specified index of the array.
- array
- The one-dimensional Array that is the destination of the elements copied from the current instance. The System.Array.Length of this array is greater than or equal to the sum of arrayIndex and the System.Collections.ArrayList.Count of the current instance.
- arrayIndex
- A Int32 that specifies the first index of array to which the elements of the current instance are copied. This value is greater than or equal to zero, and less than array.Length.
Exception Type Condition ArgumentNullException array is null
.ArgumentOutOfRangeException arrayIndex < 0. ArgumentException array has more than one dimension. -or-
arrayIndex >= array.Length.
-or-
arrayIndex + System.Collections.ArrayList.Count of the current instance > array.Length.
InvalidCastException At least one element in the current instance is not assignment-compatible with the type of array.
[Note: This method is implemented to support the IList interface.]
[Behaviors: As described above.]
[Default: This method uses System.Array.Copy(System.Array,System.Array,System.Int32) to copy the current instance to array.]
System.Collections.ArrayList Class, System.Collections Namespace
public virtual void CopyTo(int index, Array array, int arrayIndex, int count);
Copies the specified range of elements from the current instance to the specified Array, starting at the specified index of the array.
- index
- A Int32 that specifies the index in the current instance at which copying begins. This value is greater than or equal to 0, and less than the System.Collections.ArrayList.Count of the current instance.
- array
- The one-dimensional Array that is the destination of the elements copied from the current instance.
- arrayIndex
- A Int32 that specifies the first index of array to which the elements of the current instance are copied. This value is greater than or equal to zero, and less than array.Length minus count.
- count
- A Int32 that specifies the number of elements to copy. This value is greater than or equal to 0, and less than both the System.Collections.ArrayList.Count of the current instance minus index and array.Length minus arrayIndex.
Exception Type Condition ArgumentNullException array is null
.ArgumentOutOfRangeException index < 0. -or-
arrayIndex < 0.
-or-
count < 0.
ArgumentException array has more than one dimension. -or-
index >= System.Collections.ArrayList.Count of the current instance .
-or-
count >= System.Collections.ArrayList.Count of the current instance - index.
-or-
count >= array.Length - arrayIndex.
InvalidCastException At least one element of the current instance is not assignment-compatible with the type of array.
[Behaviors: As described above.]
[Default: This method uses System.Array.Copy(System.Array,System.Array,System.Int32) to copy the current instance to array.]
System.Collections.ArrayList Class, System.Collections Namespace
public virtual void CopyTo(Array array);
Copies the elements from the current instance to the specified Array.
- array
- The one-dimensional Array that is the destination of the elements copied from the current instance. The System.Array.Length of this array is greater than or equal to the System.Collections.ArrayList.Count of the current instance.
Exception Type Condition ArgumentNullException array is null
.ArgumentException array has more than one dimension. -or-
System.Collections.ArrayList.Count of the current instance > array.Length.
InvalidCastException At least one element in the current instance is not assignment-compatible with the type of array.
[Behaviors: As described above.]
[Default: This method uses System.Array.Copy(System.Array,System.Array,System.Int32) to copy the current instance to array.]
System.Collections.ArrayList Class, System.Collections Namespace
public static ArrayList FixedSize(ArrayList list);
Returns a ArrayList wrapper with a fixed size.
- list
- The ArrayList to wrap.
A ArrayList wrapper with a fixed size.
Exception Type Condition ArgumentNullException list is null
.
This method returns a fixed-size ArrayList that contains a reference to list. Operations that attempt add to or delete from this new list will throw NotSupportedException. Any modifications of the elements in either the returned list or list will be reflected in the other.[Note: The System.Collections.ArrayList.IsFixedSize property of the new list is
true
. Every other property value of the new list references the same property value of list.By performing operations on the new list, this wrapper can be used to prevent additions to and deletions from the ArrayListlist. The elements of the list can still be modified by operations on the returned list.
]
System.Collections.ArrayList Class, System.Collections Namespace
public virtual IEnumerator GetEnumerator();
Returns a IEnumerator for the current instance.
A IEnumerator for the current instance.
If the elements of the current instance are modified while an enumeration is in progress, a call to System.Collections.IEnumerator.MoveNext or System.Collections.IEnumerator.Current throws InvalidOperationException .[Note: For detailed information regarding the use of an enumerator, see IEnumerator.
This property is implemented to support the IList interface.
]
[Behaviors: As described above.]
System.Collections.ArrayList Class, System.Collections Namespace
public virtual IEnumerator GetEnumerator(int index, int count);
Returns a IEnumerator for the specified section of the current instance.
- index
- A Int32 that specifies the index of the current instance before which the enumerator is initially placed. This value is greater than or equal to 0, and less than the System.Collections.ArrayList.Count of the current instance.
- count
- A Int32 that specifies the number of elements, beginning with index , in the current instance over which the enumerator can iterate. This value if greater than or equal to 0, and less than or equal to the System.Collections.ArrayList.Count of the current instance minus index .
A IEnumerator that can iterate over the range of index to index + count in the current instance.
Exception Type Condition ArgumentOutOfRangeException index < 0. -or-
count < 0.
ArgumentException index + count > System.Collections.ArrayList.Count of the current instance - index.
The enumerator only enumerates over the range of the current instance from index to index + count. If the elements of the current instance are modified while an enumeration is in progress, a call to System.Collections.IEnumerator.MoveNext or System.Collections.IEnumerator.Current will throw InvalidOperationException .[Note: For detailed information regarding the use of an enumerator, see IEnumerator.]
[Behaviors: As described above.]
[Default: The enumerator is initially placed just before the element at position index in the current instance. A call to System.Collections.IEnumerator.Reset returns the enumerator to this position.
If the enumerator is positioned over an element in the range of index -1 to index + count, and the elements of the current instance have not been modified while the enumeration was in progress, a call to System.Collections.IEnumerator.MoveNext either returns
true
and advances the enumerator one element in the current instance, or returnsfalse
and leaves the enumerator in its current position.]
System.Collections.ArrayList Class, System.Collections Namespace
public virtual ArrayList GetRange(int index, int count);
Returns a ArrayList that represents the specified range of the current instance.
- index
- A Int32 that specifies the zero-based index in the current instance at which the range starts. This value is between 0 and the System.Collections.ArrayList.Count of the current instance minus count , inclusive.
- count
- A Int32 that specifies the number of elements in the range. This value is between 0 and the System.Collections.ArrayList.Count of the current instance minus index , inclusive.
A ArrayList that represents the range in the current instance from index to index + count.
Exception Type Condition ArgumentOutOfRangeException index < 0. -or-
count < 0.
ArgumentException System.Collections.ArrayList.Count of the current instance - index < count.
[Behaviors: As described above.]
[Default: This method does not create copies of the elements: the new ArrayList instance is a view window into the source list. Therefore, all subsequent changes to the source list must be done through this view window ArrayList . If changes are made directly to the source list, the view window list is invalidated and any operations on it throw InvalidOperationException .]
System.Collections.ArrayList Class, System.Collections Namespace
public virtual int IndexOf(object value);
Searches the current instance, returning the index of the first occurrence of the specified Object.
- value
- The Object to locate in current instance.
A Int32 that specifies the index of the first occurrence of value in the current instance, if found; otherwise, -1.[Note: This provides the caller with a standard code for a failed search.]
[Note: This method is implemented to support the IList interface.]
[Behaviors: As described above.]
[Default: This method uses System.Array.IndexOf(System.Array,System.Object) to search the current instance for value .]
[Note: For the default implementation, this method performs a linear search. On average, this is an O(n/2) operation, where n is count. The longest search is an O(n) operation.]
System.Collections.ArrayList Class, System.Collections Namespace
public virtual int IndexOf(object value, int startIndex, int count);
Searches the current instance, returning the index of the first occurrence of the specified Object in the specified range.
- value
- The Object to locate in current instance.
- startIndex
- A Int32 that specifies the index at which to begin searching. This value is less than or equal to zero, and greater than the System.Collections.ArrayList.Count of the current instance.
- count
- A Int32 that specifies the number of elements to search. This value is between 0 and the System.Collections.ArrayList.Count of the current instance minus startIndex , inclusive.
A Int32 that specifies the index of the first occurrence of value in the current instance, within the range startIndex to startIndex + count , if found; otherwise, -1.[Note: This provides the caller with a standard code for a failed search.]
Exception Type Condition ArgumentOutOfRangeException startIndex>= System.Collections.ArrayList.Count of the current instance. -or-
count < 0.
-or-
count >System.Collections.ArrayList.Count of the current instance - startIndex.
[Behaviors: As described above.]
[Default: This method uses System.Array.IndexOf(System.Array,System.Object) to search the current instance for value.]
[Note: For the default implementation, this method performs a linear search. On average, this is an O(n/2) operation, where n is count. The longest search is an O(n) operation.]
System.Collections.ArrayList Class, System.Collections Namespace
public virtual int IndexOf(object value, int startIndex);
Searches the current instance, returning the index of the first occurrence of the specified Object in the specified range.
- value
- The Object to locate in current instance.
- startIndex
- A Int32 that specifies the index at which searching begins. This value is between 0 and the System.Collections.ArrayList.Count of the current instance, inclusive.
A Int32 that specifies the index of the first occurrence of value in the current instance, if found within the range startIndex to the end of the current instance; otherwise, -1.[Note: This provides the caller with a standard code for a failed search.]
Exception Type Condition ArgumentOutOfRangeException startIndex < 0. -or-
startIndex > System.Collections.ArrayList.Count of the current instance.
[Behaviors: As described above.]
[Default: This method uses System.Array.IndexOf(System.Array,System.Object) to search the current instance for value.]
[Note: For the default implementation, this method performs a linear search. On average, this is an O(n/2) operation, where n is count. The longest search is an O(n) operation.]
System.Collections.ArrayList Class, System.Collections Namespace
public virtual void Insert(int index, object value);
Inserts the specified Object into the current instance at the specified index.
- index
- A Int32 that specifies the index in the current instance at which value is inserted. This value is between 0 and the System.Collections.ArrayList.Count of the current instance, inclusive.
- value
- The Object to insert.
Exception Type Condition ArgumentOutOfRangeException index < 0. -or-
index > System.Collections.ArrayList.Count of the current instance.
NotSupportedException The current instance is read-only or has a fixed size.
[Note: This method is implemented to support the IList interface.]
[Behaviors: As described above.]
[Default: If the System.Collections.ArrayList.Count of the current instance is equal to the System.Collections.ArrayList.Capacity of the current instance, the capacity of the list is doubled by automatically reallocating the internal array before the new element is inserted. If index is equal to the System.Collections.ArrayList.Count of the current instance, value is added to the end of the current instance.]
System.Collections.ArrayList Class, System.Collections Namespace
public virtual void InsertRange(int index, ICollection c);
Inserts the elements of the specified ICollection at the specified index of the current instance.
- index
- A Int32 that specifies the index in the current instance at which the new elements are inserted. This value is between 0 and the System.Collections.ArrayList.Count of the current instance, inclusive.
- c
- The ICollection whose elements are inserted into the current instance.
Exception Type Condition ArgumentNullException c is null
.ArgumentOutOfRangeException index < 0. index > System.Collections.ArrayList.Count of the current instance.
NotSupportedException The current instance is read-only or has a fixed size.
[Behaviors: As described above.]
[Default: If the System.Collections.ArrayList.Count of the current instance plus the size of ICollectionc is greater than the System.Collections.ArrayList.Capacity of the current instance, the capacity of the current instance is either doubled or increased to the new count, whichever yields a greater capacity. The internal array is reallocated to accommodate the new elements. If index is equal to the System.Collections.ArrayList.Count of the current instance, the elements of c are added to the end of the current instance.
The order of the elements in the ICollectionc is preserved in the current instance.
]
System.Collections.ArrayList Class, System.Collections Namespace
public virtual int LastIndexOf(object value, int startIndex, int count);
Searches the current instance, returning the index of the last occurrence of the specified Object in the specified range.
- value
- The Object to locate in the current instance.
- startIndex
- A Int32 that specifies the index at which searching starts.
- count
- A Int32 that specifies the number of elements to search, beginning with startIndex .
A Int32 that specifies the index of the last occurrence of value in the current instance, within the range startIndex + count through startIndex, if found; otherwise, -1.[Note: This provides the caller with a standard code for a failed search.]
Exception Type Condition ArgumentOutOfRangeException startIndex < 0. -or-
count < 0.
-or-
startIndex >= System.Collections.ArrayList.Count of the current instance.
-or-
count >= System.Collections.ArrayList.Count of the current instance.
-or-
count >= startIndex.
[Behaviors: As described above.]
[Default: This method uses System.Array.LastIndexOf(System.Array,System.Object) to search the current instance for value.]
[Note: For the default implementation, this method performs a linear search. On average, this is an O(count/2) operation. The longest search is an O(count) operation.]
System.Collections.ArrayList Class, System.Collections Namespace
public virtual int LastIndexOf(object value, int startIndex);
Searches the current instance, returning the index of the last occurrence of the specified Object in the specified range of the current instance.
- value
- The Object to locate in the current instance.
- startIndex
- A Int32 that specifies the index at which searching starts. This value is between 0 and the System.Collections.ArrayList.Count of the current instance, inclusive.
A Int32 that specifies the index of the last occurrence of value in the range of startIndex through the first element of the current instance, if found; otherwise, -1.[Note: This provides the caller with a standard code for a failed search.]
Exception Type Condition ArgumentOutOfRangeException startIndex < 0. -or-
startIndex >= System.Collections.ArrayList.Count of the current instance.
[Behaviors: As described above.]
[Default: This method uses System.Array.LastIndexOf(System.Array,System.Object) to search the current instance for value.]
[Note: For the default implementation, this method performs a linear search. On average, this is an O(count/2) operation. The longest search is an O(count) operation.]
System.Collections.ArrayList Class, System.Collections Namespace
public virtual int LastIndexOf(object value);
Searches the current instance, returning the index of the last occurrence of the specified Object.
- value
- The Object to locate in the current instance.
A Int32 that specifies the index of the last occurrence of value in the current instance, if found; otherwise, -1.[Note: This provides the caller with a standard code for a failed search.]
[Behaviors: As described above.]
[Default: This method uses System.Array.LastIndexOf(System.Array,System.Object) to search the current instance for value.]
[Note: For the default implementation, this method performs a linear search. On average, this is an O(n/2) operation, where n is System.Collections.ArrayList.Count of the current instance. The longest search is an O(n) operation.]
System.Collections.ArrayList Class, System.Collections Namespace
public static ArrayList ReadOnly(ArrayList list);
Returns a read-only ArrayList wrapper.
- list
- The ArrayList to wrap.
A read-only ArrayList wrapper around list.
Exception Type Condition ArgumentNullException list is null
.
This method returns a read-only ArrayList that contains a reference to list. Operations that attempt add to, delete from, or modify the elements of this new list will throw NotSupportedException. Any modifications of the elements list will be reflected in the new list.[Note: The System.Collections.ArrayList.IsReadOnly property of the new list is
true
. Every other property value of the new list references the same property value of list.By performing operations on the new list, this wrapper can be used to prevent additions to, deletions from, and modifications of the ArrayListlist.
]
System.Collections.ArrayList Class, System.Collections Namespace
public virtual void Remove(object obj);
Removes the first occurrence of the specified Object from the current instance.
- obj
- The Object to remove from the current instance.
Exception Type Condition NotSupportedException The current instance is read-only or has a fixed size.
[Note: This method is implemented to support the IList interface.]
[Behaviors: As described above.]
[Default: This method determines equality by calling System.Object.Equals(System.Object).
If and only if obj is found in the current instance, obj is removed from the current instance, the rest of the elements are shifted down to fill the position vacated by obj, the System.Collections.ArrayList.Count of the current instance is decreased by one, and the position that was previously the last element in the current instance is set to
null
. If obj is not found in the current instance, the current instance remains unchanged.]
[Note: For the default implementation, this method performs a linear search. On average, this is an O(n/2) operation, where n is System.Collections.ArrayList.Count of the current instance. The longest search is an O(n) operation.]
System.Collections.ArrayList Class, System.Collections Namespace
public virtual void RemoveAt(int index);
Removes the element at the specified index from the current instance.
- index
- A Int32 that specifies the zero-based index of the element to remove from the current instance. This value is between 0 and the System.Collections.ArrayList.Count of the current instance, inclusive.
Exception Type Condition ArgumentOutOfRangeException index < 0. -or-
index >= System.Collections.ArrayList.Count of the current instance.
NotSupportedException The current instance is read-only or has a fixed size.
[Note: This method is implemented to support the IList interface.]
[Behaviors: As described above.]
[Default: The element at position index is removed from the current instance, the rest of the elements are shifted down to fill the position vacated by that element, the System.Collections.ArrayList.Count of the current instance is decreased by one, and the position that was previously the last element in the current instance is set to
null
.]
System.Collections.ArrayList Class, System.Collections Namespace
public virtual void RemoveRange(int index, int count);
Removes the specified range of elements from the current instance.
- index
- A Int32 that specifies the zero-based index of the first element of the range of elements in the current instance to remove. This value is between 0 and the System.Collections.ArrayList.Count of the current instance minus count , inclusive.
- count
- A Int32 that specifies the number of elements to remove. This value is between 0 and the System.Collections.ArrayList.Count of the current instance minus index , inclusive.
Exception Type Condition ArgumentOutOfRangeException index < 0. -or-
count < 0.
ArgumentException System.Collections.ArrayList.Count of the current instance - index < count. NotSupportedException The current instance is read-only or has a fixed size.
[Behaviors: As described above.]
[Default: The elements in the range of index to index + count are removed from the current instance, the rest of the elements are shifted down to fill the position vacated by those elements, the System.Collections.ArrayList.Count of the current instance is decreased by count, and the count positions that were previously the last elements in the current instance are set to
null
.]
System.Collections.ArrayList Class, System.Collections Namespace
public static ArrayList Repeat(object value, int count);
Returns a new ArrayList whose elements are copies of the specified Object.
- value
- The Object used to initialize the new ArrayList instance.
- count
- A Int32 that specifies the number of times value is copied into the new ArrayList instance.
A new ArrayList with count number of elements, all of which are copies of value.
Exception Type Condition ArgumentOutOfRangeException count < 0.
If count is less than the default initial capacity, 16, the System.Collections.ArrayList.Capacity of the new ArrayList instance is set to the default initial capacity. Else, the capacity is set to count . The System.Collections.ArrayList.Count of the new instance is set to count.
System.Collections.ArrayList Class, System.Collections Namespace
public virtual void Reverse(int index, int count);
Reverses the sequence of the elements in the specified range of the current instance.
- index
- A Int32 that specifies the zero-based index in the current instance at which reversing starts. This value is between 0 and the System.Collections.ArrayList.Count of the current instance minus count , inclusive.
- count
- A Int32 that specifies the number of elements to reverse. This value is between 0 and the System.Collections.ArrayList.Count of the current instance minus index , inclusive.
Exception Type Condition ArgumentOutOfRangeException index < 0. -or-
count < 0.
ArgumentException System.Collections.ArrayList.Count of the current instance - index < count.
NotSupportedException The current instance is read-only.
[Behaviors: As described above.]
[Default: This method uses System.Array.Reverse(System.Array) to modify the ordering of the current instance.]
System.Collections.ArrayList Class, System.Collections Namespace
public virtual void Reverse();
Reverses the sequence of the elements in the current instance.
Exception Type Condition NotSupportedException The current instance is read-only.
[Behaviors: As described above.]
[Default: This method uses System.Array.Reverse(System.Array) to modify the ordering of the elements in the current instance.]
System.Collections.ArrayList Class, System.Collections Namespace
public virtual void SetRange(int index, ICollection c);
Copies the elements of the specified ICollection to a range in the current instance.
- index
- A Int32 that specifies the zero-based index in the current instance at which to start copying the elements of c. This value is between 0 and the System.Collections.ArrayList.Count of the current instance minus c.Count, inclusive.
- c
- The ICollection whose elements to copy to the current instance.
Exception Type Condition ArgumentOutOfRangeException index < 0. -or-
System.Collections.ArrayList.Count of the current instance - index < c.Count.
ArgumentNullException c is null
.NotSupportedException The current instance is read-only.
[Behaviors: As described above.]
[Default: This method uses the System.Collections.ICollection.CopyTo(System.Array,System.Int32) implementation of ICollectionc.]
System.Collections.ArrayList Class, System.Collections Namespace
public virtual void Sort(int index, int count, IComparer comparer);
Sorts the elements in the specified range of the current instance using the specified IComparer implementation.
- index
- A Int32 that specifies the zero-based index at which sorting starts. This value is between 0 and the System.Collections.ArrayList.Count of the current instance minus count , inclusive.
- count
- A Int32 that specifies the number of elements to sort. This value is between 0 and the System.Collections.ArrayList.Count of the current instance minus index , inclusive.
- comparer
- The IComparer implementation to use when comparing elements. Specify
null
to use the IComparable implementation of each element in the current instance.
Exception Type Condition ArgumentOutOfRangeException index < 0. -or-
count < 0.
ArgumentException System.Collections.ArrayList.Count of the current instance - index < count.
InvalidCastException comparer is null
, and one or more elements in the current instance do not implement the IComparable interface.NotSupportedException The current instance is read-only.
[Behaviors: As described above.]
[Default: If comparer is
null
, the IComparable implementation of each element in the current instance is used to make the sorting comparisons. If the sort is not successfully completed, the results are unspecified.]
[Note: For the default implementation, this method uses System.Array.Sort(System.Array), which uses the Quicksort algorithm. This is an O(n log2n) operation, where n is the number of elements to sort.]
System.Collections.ArrayList Class, System.Collections Namespace
public virtual void Sort(IComparer comparer);
Sorts the elements of current instance using the specified IComparer.
- comparer
- The IComparer implementation to use when comparing elements. Specify
null
to use the IComparable implementation of each element in the current instance.
Exception Type Condition InvalidCastException comparer is null
, and one or more elements in the current instance do not implement the IComparable interface.NotSupportedException The current instance is read-only.
[Behaviors: As described above.]
[Default: If comparer is
null
, the IComparable implementation of each element in the current instance is used to make the sorting comparisons. If the sort is not successfully completed, the results are unspecified.]
[Note: For the default implementation, this method uses System.Array.Sort(System.Array), which uses the Quicksort algorithm. This is an O(n log2n) operation, where n is the number of elements to sort.]
System.Collections.ArrayList Class, System.Collections Namespace
public virtual void Sort();
Sorts the elements of the current instance.
Exception Type Condition InvalidCastException One or more elements in the current instance do not implement the IComparable interface. NotSupportedException The current instance read-only.
[Behaviors: As described above.]
[Default: The IComparable implementation of each element in the current instance is used to make the sorting comparisons. If the sort is not successfully completed, the results are unspecified.]
[Note: For the default implementation, this method uses System.Array.Sort(System.Array), which uses the Quicksort algorithm. This is an O(n log2n) operation, where n is the number of elements to sort.]
System.Collections.ArrayList Class, System.Collections Namespace
public static ArrayList Synchronized(ArrayList list);
Returns a ArrayList wrapper around the specified ArrayList that is synchronized (thread-safe).
- list
- The ArrayList to synchronize.
A ArrayList wrapper that is synchronized (thread-safe).
Exception Type Condition ArgumentNullException list is null
.
This method returns a thread-safe ArrayList that contains a reference to list. Any modifications of the elements in either the returned list or list will be reflected in the other.[Note: The System.Collections.ArrayList.IsSynchronized property of the new list is
true
. Every other property value of the new list references the same property value of list.By performing operations on the new list, this wrapper can be used to guarantee thread-safe access to the ArrayListlist.
]
System.Collections.ArrayList Class, System.Collections Namespace
public virtual Array ToArray(Type type);
Copies the elements of the current instance to a new array of the specified Type.
- type
- The Type of the Array to create and copy the elements of the current instance.
An array of Typetype containing copies of the elements of the current instance.
Exception Type Condition ArgumentNullException type is null
.InvalidCastException At least one element of the current instance cannot be cast to the Typetype.
[Behaviors: As described above.]
[Default: The elements are copied using System.Array.Copy(System.Array,System.Array,System.Int32).]
[Note: For the default implementation, this method is an O(n) operation, where n is the System.Collections.ArrayList.Count of the current instance.]
System.Collections.ArrayList Class, System.Collections Namespace
public virtual object[] ToArray();
Copies the elements of the current instance to a new Object array.
A Object array containing copies of the elements of the current instance.
[Behaviors: As described above.]
[Default: The elements are copied using System.Array.Copy(System.Array,System.Array,System.Int32).]
[Note: For the default implementation, this method is an O(n) operation, where n is the System.Collections.ArrayList.Count of the current instance.]
System.Collections.ArrayList Class, System.Collections Namespace
public virtual void TrimToSize();
Sets the System.Collections.ArrayList.Capacity of the current instance to the System.Collections.ArrayList.Count of the current instance.
Exception Type Condition NotSupportedException The current instance is read-only or has a fixed size.
[Note: This method can be used to minimize the memory overhead of the current instance if no new elements will be added to it.To completely clear all elements from the current instance, call the System.Collections.ArrayList.Clear method before calling System.Collections.ArrayList.TrimToSize.
]
[Behaviors: As described above.]
[Default: If the System.Collections.ArrayList.Count of the current instance is zero, the System.Collections.ArrayList.Capacity of the current instance is set to the default initial capacity of 16.]
System.Collections.ArrayList Class, System.Collections Namespace
public virtual int Capacity { get; set; }
Gets or sets the number of elements that the current instance is capable of storing.
A Int32 that specifies the number of elements that the current instance is capable of storing.
Exception Type Condition ArgumentOutOfRangeException System.Collections.ArrayList.Capacity is set to a value that is less than the System.Collections.ArrayList.Count of the current instance.
[Note: The System.Collections.ArrayList.Capacity of a ArrayList is the size of the internal array used to hold the elements of that list. When it is set, the internal array is reallocated to the specified value.]
[Behaviors: As described above.]
[Default: If an attempt is made to set System.Collections.ArrayList.Capacity to a value less or equal to 0, it is set to the default capacity of 16.
If the System.Collections.ArrayList.Count of the current instance exceeds the System.Collections.ArrayList.Capacity of the current instance while adding elements to the current instance, the capacity of the list is doubled by automatically reallocating the internal array before copying the old elements and adding the new elements.
]
System.Collections.ArrayList Class, System.Collections Namespace
int ICollection.Count { get; }
Implemented to support the ICollection interface. [Note: For more information, see System.Collections.ICollection.Count.]
System.Collections.ArrayList Class, System.Collections Namespace
public virtual int Count { get; }
Gets the number of elements contained in the current instance.
A Int32 that specifies the number of elements contained in the current instance.
This property is read-only.System.Collections.ArrayList.Count is the number of elements that are contained by the ArrayList. The count of a list is always less than or equal to System.Collections.ArrayList.Capacity of that list.
[Note: This property is implemented to support the IList interface.]
[Behaviors: As described above.]
[Default: If the System.Collections.ArrayList.Count exceeds the System.Collections.ArrayList.Capacity of the current instance while adding elements to the current instance, the capacity of the list is doubled by automatically reallocating the internal array before copying the old elements and adding the new elements.]
System.Collections.ArrayList Class, System.Collections Namespace
bool IList.IsFixedSize { get; }
Implemented to support the IList interface. [Note: For more information, see System.Collections.IList.IsFixedSize.]
System.Collections.ArrayList Class, System.Collections Namespace
public virtual bool IsFixedSize { get; }
Gets a Boolean indicating whether the System.Collections.ArrayList.Capacity of the current instance cannot be changed.
true
if the System.Collections.ArrayList.Capacity of the current instance cannot be changed; otherwise,false
.
This property is read-only.[Note: Elements cannot be added or removed from a ArrayList with a fixed size, while existing elements can be modified.
This property is implemented to support the IList interface.
]
[Behaviors: As described above.]
[Default: The default value for this property is
false
.]
System.Collections.ArrayList Class, System.Collections Namespace
bool IList.IsReadOnly { get; }
Implemented to support the IList interface. [Note: For more information, see System.Collections.IList.IsReadOnly.]
System.Collections.ArrayList Class, System.Collections Namespace
public virtual bool IsReadOnly { get; }
Gets a value indicating whether the current instance is read-only.
true
if the current instance is read-only; otherwise,false
.
This property is read-only.[Note: The elements of a ArrayList that is read-only cannot be modified, nor can elements be added to or removed from that list.
This property is implemented to support the IList interface.
]
[Behaviors: As described above.]
[Default: The default value of this property is
false
.]
System.Collections.ArrayList Class, System.Collections Namespace
bool ICollection.IsSynchronized { get; }
Implemented to support the ICollection interface. [Note: For more information, see System.Collections.ICollection.IsSynchronized.]
System.Collections.ArrayList Class, System.Collections Namespace
public virtual bool IsSynchronized { get; }
Gets a value indicating whether access to the current instance is synchronized (thread-safe).
true
if access to the current instance is synchronized (thread-safe); otherwise,false
.
This property is read-only.To guarantee the thread safety of the ArrayList, all operations must be done through the wrapper returned by the System.Collections.ArrayList.Synchronized(System.Collections.IList) method.
[Note: This property is implemented to support the IList interface.]
[Behaviors: As described above.]
[Default: The default value of this property is
false
.]
System.Collections.ArrayList Class, System.Collections Namespace
public virtual object this[int index] { get; set; }
Gets or sets the element at the specified index of the current instance.
- index
- A Int32 that specifies the zero-based index of the element in the current instance to get or set. This value is greater than or equal to 0, and less than the System.Collections.ArrayList.Count of the current instance.
The element at the specified index of the current instance.
Exception Type Condition ArgumentOutOfRangeException index < 0. -or-
index >= System.Collections.ArrayList.Count of the current instance.
[Note: This property provides the ability to access a specific element in the collection by using the following syntax:myCollection[index]
.This property is implemented to support the IList interface.
]
[Behaviors: As described above.]
System.Collections.ArrayList Class, System.Collections Namespace
object ICollection.SyncRoot { get; }
Implemented to support the ICollection interface. [Note: For more information, see System.Collections.ICollection.SyncRoot.]
System.Collections.ArrayList Class, System.Collections Namespace
public virtual object SyncRoot { get; }
Gets an object that can be used to synchronize access to the current instance.
A Object that can be used to synchronize access to the current instance.
This property is read-only.Program code must perform synchronized operations on the System.Collections.ArrayList.SyncRoot of the current instance, not directly on the current instance. This ensures proper operation of collections that are derived from other objects. Specifically, it maintains proper synchronization with other threads that might be simultaneously modifying the current instance.
[Behaviors: As described above.]
[Default: This method returns a reference to the current instance.]
[Note: This property is implemented to support the IList interface.]
System.Collections.ArrayList Class, System.Collections Namespace