Class ObjectCollection

Represents a strongly typed collection of objects that can be accessed by index. This class provides a basic implementation of a dynamic array.

Constructors

Initializes a new instance of the ObjectCollection class that is empty and has the default initial capacity.

Initializes a new instance of the ObjectCollection class that is empty and has the specified initial capacity.

public ObjectCollection(int capacity);
  • capacity int - The number of elements that the new list can initially store.
Methods

Appends a value to the end of the ObjectCollection.

public void Add(object value);
  • value object - The object value to append to the end of the ObjectCollection.
Clear() void

Removes all objects from the ObjectCollection.

public void Clear();

Determines whether an element is in the ObjectCollection.

public bool Contains(object value);
  • value object - The object to search for in the ObjectCollection.

Return Value

true if the element is found in the ObjectCollection; otherwise, false.

Gets the zero-based index of the first occurrence of the specified Object within the entire ObjectCollection.

public int IndexOf(object value);
  • value object - The Object to locate in the ObjectCollection.

Return Value

The zero-based index of the first occurrence of the specified Object within the entire ObjectCollection, or -1 if the object is not found.

Inserts an element into the ObjectCollection at the specified index.

public void Insert(int index, object value);
  • index int - The zero-based index at which value should be inserted.
  • value object - The Object to insert into the ObjectCollection.
Properties
Count int

Gets the number of elements actually contained in the ObjectCollection.

public int Count { get; }

Return Value

The number of elements actually contained in the ObjectCollection.

Gets or sets the element at the specified index.

public object this[int index] { get; set; }
  • index int - The zero-based index of the element to get or set.

Return Value

The element at the specified index. If the property is being set, the value of the element at the specified index.

Remarks

The ObjectCollection class is a lightweight implementation of a dynamic array that can store any type of object. It is derived from CollectionBase, providing basic collection management functionality. This class is useful when you need a collection that can grow dynamically and allows access to its elements by index.

It supports adding, inserting, and retrieving elements by index, as well as checking for the existence of an element and clearing the collection. The capacity of the collection automatically increases as needed.