[Serializable] |
This implementation does not provide a synchronized (thread-safe) wrapper for a CollectionBase, but derived classes can create their own synchronized versions of the CollectionBase using the CollectionBase.System.Collections.ICollection.SyncRoot property.
Enumerating through a collection is intrinsically not a thread-safe procedure. Even when a collection is synchronized, other threads could still modify the collection, which causes the enumerator to throw an exception. To guarantee thread safety during enumeration, you can either lock the collection during the entire enumeration or catch the exceptions resulting from changes made by other threads.
Count | Read-only Gets the number of elements contained in the CollectionBase instance. |
Clear | Removes all objects from the CollectionBase instance. |
Equals (inherited from System.Object) |
See base class member description: System.Object.Equals Derived from System.Object, the primary base class for all objects. |
GetEnumerator | Returns an enumerator that can iterate through the CollectionBase instance. |
GetHashCode (inherited from System.Object) |
See base class member description: System.Object.GetHashCode Derived from System.Object, the primary base class for all objects. |
GetType (inherited from System.Object) |
See base class member description: System.Object.GetType Derived from System.Object, the primary base class for all objects. |
RemoveAt | Removes the element at the specified index of the CollectionBase instance. |
ToString (inherited from System.Object) |
See base class member description: System.Object.ToString Derived from System.Object, the primary base class for all objects. |
ctor #1 | Default constructor. This constructor is called by derived class constructors to initialize state in this type. |
InnerList | Read-only Gets an ArrayList containing the list of elements in the CollectionBase instance. |
List | Read-only Gets an IList containing the list of elements in the CollectionBase instance. |
Finalize (inherited from System.Object) |
See base class member description: System.Object.Finalize Derived from System.Object, the primary base class for all objects. |
MemberwiseClone (inherited from System.Object) |
See base class member description: System.Object.MemberwiseClone Derived from System.Object, the primary base class for all objects. |
OnClear | Performs additional custom processes when clearing the contents of the CollectionBase instance. |
OnClearComplete | Performs additional custom processes after clearing the contents of the CollectionBase instance. |
OnInsert | Performs additional custom processes before inserting a new element into the CollectionBase instance. |
OnInsertComplete | Performs additional custom processes after inserting a new element into the CollectionBase instance. |
OnRemove | Performs additional custom processes when removing an element from the CollectionBase instance. |
OnRemoveComplete | Performs additional custom processes after removing an element from the CollectionBase instance. |
OnSet | Performs additional custom processes before setting a value in the CollectionBase instance. |
OnSetComplete | Performs additional custom processes after setting a value in the CollectionBase instance. |
OnValidate | Performs additional custom processes when validating a value. |
ICollection.CopyTo | Copies the entire CollectionBase to a compatible one-dimensional Array, starting at the specified index of the target array. |
IList.Add | Adds an object to the end of the CollectionBase. |
IList.Contains | Determines whether the CollectionBase contains a specific element. |
IList.IndexOf | Searches for the specified Object and returns the zero-based index of the first occurrence within the entire CollectionBase. |
IList.Insert | Inserts an element into the CollectionBase at the specified index. |
IList.Remove | Removes the first occurrence of a specific object from the CollectionBase. |
Hierarchy:
protected CollectionBase(); |
public int Count {get;}
|
protected ArrayList InnerList {get;}
|
protected IList List {get;}
|
public void Clear(); |
~CollectionBase(); |
public IEnumerator GetEnumerator(); |
Initially, the enumerator is positioned before the first element in the collection. IEnumerator.Reset also brings the enumerator back to this position. At this position, calling IEnumerator.Current throws an exception. Therefore, you must call IEnumerator.MoveNext to advance the enumerator to the first element of the collection before reading the value of IEnumerator.Current.
IEnumerator.Current returns the same object until either IEnumerator.MoveNext or IEnumerator.Reset is called. IEnumerator.MoveNext sets IEnumerator.Current to the next element.
After the end of the collection is passed, the enumerator is positioned after the last element in the collection, and calling IEnumerator.MoveNext returns false. If the last call to IEnumerator.MoveNext returned false, calling IEnumerator.Current throws an exception. To set IEnumerator.Current to the first element of the collection again, you can call IEnumerator.Reset followed by IEnumerator.MoveNext.
An enumerator remains valid as long as the collection remains unchanged. If changes are made to the collection, such as adding, modifying or deleting elements, the enumerator is irrecoverably invalidated and the next call to IEnumerator.MoveNext or IEnumerator.Reset throws an InvalidOperationException. If the collection is modified between IEnumerator.MoveNext and IEnumerator.Current, IEnumerator.Current will return the element that it is set to, even if the enumerator is already invalidated.
The enumerator does not have exclusive access to the collection; therefore, enumerating through a collection is intrinsically not a thread-safe procedure. Even when a collection is synchronized, other threads could still modify the collection, which causes the enumerator to throw an exception. To guarantee thread safety during enumeration, you can either lock the collection during the entire enumeration or catch the exceptions resulting from changes made by other threads.
public virtual int GetHashCode(); |
public Type GetType(); |
protected object MemberwiseClone(); |
protected virtual void OnClear(); |
The On* methods are invoked only on the instance returned by the CollectionBase.List property, but not on the instance returned by the CollectionBase.InnerList property.
This method allows implementers to define processes that must be performed before deleting all the elements from the underlying ArrayList. By defining this method, implementers can add functionality to inherited methods without having to override all other methods.
CollectionBase.OnClear is invoked before the standard Clear behavior, whereas CollectionBase.OnClearComplete is invoked after the standard Clear behavior.
For example, implementers can exempt certain elements from deletion by a global Clear.
protected virtual void OnClearComplete(); |
The On* methods are invoked only on the instance returned by the CollectionBase.List property, but not on the instance returned by the CollectionBase.InnerList property.
This method allows implementers to define processes that must be performed after deleting all the elements from the underlying ArrayList. By defining this method, implementers can add functionality to inherited methods without having to override all other methods.
CollectionBase.OnClear is invoked before the standard Clear behavior, whereas CollectionBase.OnClearComplete is invoked after the standard Clear behavior.
index
value
The On* methods are invoked only on the instance returned by the CollectionBase.List property, but not on the instance returned by the CollectionBase.InnerList property.
This method allows implementers to define processes that must be performed before inserting the element into the underlying ArrayList. By defining this method, implementers can add functionality to inherited methods without having to override all other methods.
CollectionBase.OnInsert is invoked before the standard Insert behavior, whereas CollectionBase.OnInsertComplete is invoked after the standard Insert behavior.
For example, implementers can restrict which types of objects can be inserted into the ArrayList.
index
value
The On* methods are invoked only on the instance returned by the CollectionBase.List property, but not on the instance returned by the CollectionBase.InnerList property.
This method allows implementers to define processes that must be performed after inserting the element into the underlying ArrayList. By defining this method, implementers can add functionality to inherited methods without having to override all other methods.
CollectionBase.OnInsert is invoked before the standard Insert behavior, whereas CollectionBase.OnInsertComplete is invoked after the standard Insert behavior.
index
value
The On* methods are invoked only on the instance returned by the CollectionBase.List property, but not on the instance returned by the CollectionBase.InnerList property.
This method allows implementers to define processes that must be performed before removing the element from the underlying ArrayList. By defining this method, implementers can add functionality to inherited methods without having to override all other methods.
CollectionBase.OnRemove is invoked before the standard Remove behavior, whereas CollectionBase.OnRemoveComplete is invoked after the standard Remove behavior.
For example, implementers can prevent removal of elements by always throwing an exception in CollectionBase.OnRemove.
index
value
The On* methods are invoked only on the instance returned by the CollectionBase.List property, but not on the instance returned by the CollectionBase.InnerList property.
This method allows implementers to define processes that must be performed after removing the element from the underlying ArrayList. By defining this method, implementers can add functionality to inherited methods without having to override all other methods.
CollectionBase.OnRemove is invoked before the standard Remove behavior, whereas CollectionBase.OnRemoveComplete is invoked after the standard Remove behavior.
index
oldValue
newValue
The On* methods are invoked only on the instance returned by the CollectionBase.List property, but not on the instance returned by the CollectionBase.InnerList property.
This method allows implementers to define processes that must be performed before setting the specified element in the underlying ArrayList. By defining this method, implementers can add functionality to inherited methods without having to override all other methods.
CollectionBase.OnSet is invoked before the standard Set behavior, whereas CollectionBase.OnSetComplete is invoked after the standard Set behavior.
For example, implementers can restrict which values can be overwritten by performing a check inside CollectionBase.OnSet.
index
oldValue
newValue
The On* methods are invoked only on the instance returned by the CollectionBase.List property, but not on the instance returned by the CollectionBase.InnerList property.
This method allows implementers to define processes that must be performed after setting the specified element in the underlying ArrayList. By defining this method, implementers can add functionality to inherited methods without having to override all other methods.
CollectionBase.OnSet is invoked before the standard Set behavior, whereas CollectionBase.OnSetComplete is invoked after the standard Set behavior.
protected virtual void OnValidate( |
value
The On* methods are invoked only on the instance returned by the CollectionBase.List property, but not on the instance returned by the CollectionBase.InnerList property.
This method allows implementers to define processes that must be performed when executing the standard behavior of the underlying ArrayList. By defining this method, implementers can add functionality to inherited methods without having to override all other methods.
CollectionBase.OnValidate can be used to impose restrictions on the type of objects that are accepted into the collection. The default implementation prevents null from being added to or removed from the underlying ArrayList.
public void RemoveAt( |
index
Exception Type | Condition |
---|---|
ArgumentOutOfRangeException | index is less than zero. -or- index is equal to or greater than CollectionBase.Count. |
array
index
Exception Type | Condition |
---|---|
ArgumentNullException | array is null. |
ArgumentOutOfRangeException | index is less than zero. |
ArgumentException | array is multidimensional. -or- index is equal to or greater than the length of array. -or- The number of elements in the source CollectionBase is greater than the available space from index to the end of the destination array. |
InvalidCastException | The type of the source CollectionBase cannot be cast automatically to the type of the destination array. |
This method uses Array.Copy to copy the elements.
value
Exception Type | Condition |
---|---|
NotSupportedException | The CollectionBase is read-only. -or- The CollectionBase has a fixed size. |
If CollectionBase.Count is less than the capacity, this method is an O(1) operation. If the capacity needs to be increased to accommodate the new element, this method becomes an O(n) operation, where n is CollectionBase.Count.
value
This method determines equality by calling Object.Equals.
value
This method determines equality by calling Object.Equals.
index
value
Exception Type | Condition |
---|---|
ArgumentOutOfRangeException | index is less than zero. -or- index is greater than CollectionBase.Count. |
NotSupportedException | The CollectionBase is read-only. -or- The CollectionBase has a fixed size. |
If index is equal to CollectionBase.Count, value is added to the end of CollectionBase.
In collections of contiguous elements, such as lists, the elements that follow the insertion point move down to accomodate the new element. If the collection is indexed, the indexes of the elements that are moved are also updated. This behavior does not apply to collections where elements are conceptually grouped into buckets, such as a hashtable.
void IList.Remove( |
value
Exception Type | Condition |
---|---|
NotSupportedException | The CollectionBase is read-only. -or- The CollectionBase has a fixed size. |
This method determines equality by calling Object.Equals.
In collections of contiguous elements, such as lists, the elements that follow the removed element move up to occupy the vacated spot. If the collection is indexed, the indexes of the elements that are moved are also updated. This behavior does not apply to collections where elements are conceptually grouped into buckets, such as a hashtable.
public virtual string ToString(); |