Class BaseCollection<T>
Provides the base class for all generic collections.
Inheritance
Implements
Inherited Members
Namespace: Nevatech.Vsb.Repository
Assembly: Nevatech.Vsb.Repository.dll
Syntax
public class BaseCollection<T> : IList<T>, ICollection<T>, IEnumerable<T>, IEnumerable
Type Parameters
Name | Description |
---|---|
T | The type of elements in the collection. |
Constructors
BaseCollection()
Creates a new instance and ensures that base collection class uses generic list as underlying storage for improved performance.
Declaration
public BaseCollection()
BaseCollection(IEnumerable<T>)
Creates a new instance and uses the specified collection for initial population.
Declaration
public BaseCollection(IEnumerable<T> collection)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<T> | collection | The initial collection of objects to populate this collection. |
Properties
Count
Gets the number of elements in this collection.
Declaration
public int Count { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
IsReadOnly
Gets the flag that indicates if this collection is read-only.
Declaration
public virtual bool IsReadOnly { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Item[Int32]
Gets or sets the collection element by index.
Declaration
public virtual T this[int index] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | The zero-based index within this collection. |
Property Value
Type | Description |
---|---|
T | The element at the specified index in this collection. |
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException | Thrown if the specified index is out of range. |
Methods
Add(T)
Adds a new element to this collection.
Declaration
public virtual void Add(T item)
Parameters
Type | Name | Description |
---|---|---|
T | item | The element to add; can be null. |
AddRange(IEnumerable<T>)
Adds elements of an System.Collections.Generic.IEnumerable<T> to the end of this collection.
Declaration
public void AddRange(IEnumerable<T> collection)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<T> | collection | The System.Collections.Generic.IEnumerable<T> collection whose elements should be added. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | Thrown if the specified collection is a null reference. |
AsReadOnly()
Returns a read-only wrapper for this collection.
Declaration
public ReadOnlyCollection<T> AsReadOnly()
Returns
Type | Description |
---|---|
System.Collections.ObjectModel.ReadOnlyCollection<T> | A System.Collections.ObjectModel.ReadOnlyCollection<T> object that is a read-only wrapper for this collection. |
BinarySearch(T)
Searches the entire sorted collection for an element using the default comparer and returns the zero-based index of the element.
Declaration
public int BinarySearch(T item)
Parameters
Type | Name | Description |
---|---|---|
T | item | The element for which to search. |
Returns
Type | Description |
---|---|
System.Int32 | The zero based index of an element. |
BinarySearch(T, IComparer<T>)
Searches the entire sorted collection for an element using the specified comparer and returns the zero-based index of the element.
Declaration
public int BinarySearch(T item, IComparer<T> comparer)
Parameters
Type | Name | Description |
---|---|---|
T | item | The element for which to search. |
System.Collections.Generic.IComparer<T> | comparer | The System.Collections.Generic.IComparer<T> implementation to use when comparing elements. |
Returns
Type | Description |
---|---|
System.Int32 | The zero based index of an element. |
Clear()
Clears this collection.
Declaration
public virtual void Clear()
Contains(T)
Checks if the specified item is in this collection.
Declaration
public virtual bool Contains(T item)
Parameters
Type | Name | Description |
---|---|---|
T | item | The item to find. |
Returns
Type | Description |
---|---|
System.Boolean | True if item is found; otherwise, false. |
CopyTo(T[], Int32)
Copies elements from this collection to the specified array.
Declaration
public void CopyTo(T[] array, int arrayIndex)
Parameters
Type | Name | Description |
---|---|---|
T[] | array | The array to which to copy elements. |
System.Int32 | arrayIndex | The array index at which to start. |
Find(Func<T, Object, Boolean>, Object)
Searches for an item within this collection using the specified element matching function.
Declaration
public T Find(Func<T, object, bool> match, object value)
Parameters
Type | Name | Description |
---|---|---|
System.Func<T, System.Object, System.Boolean> | match | Function that evaluates the search condition. |
System.Object | value | A value to search for. |
Returns
Type | Description |
---|---|
T | The item of type T if found; otherwise, default T value. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | Thrown if the specified predicate is a null reference. |
GetEnumerator()
Gets the System.Collections.Generic.IEnumerator<T> interface that can be used to iterate through this collection.
Declaration
public IEnumerator<T> GetEnumerator()
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerator<T> | The System.Collections.Generic.IEnumerator<T> interface. |
IndexOf(T)
Searches for the specified object and returns the zero-based index of the first occurrence.
Declaration
public virtual int IndexOf(T item)
Parameters
Type | Name | Description |
---|---|---|
T | item | The object to locate. The value can be a null reference. |
Returns
Type | Description |
---|---|
System.Int32 | The zero-based index of the first occurrence of |
IndexOf(T, Int32)
Searches for the specified object and returns the zero-based index of the first occurrence.
Declaration
public virtual int IndexOf(T item, int index)
Parameters
Type | Name | Description |
---|---|---|
T | item | The object to locate. The value can be a null reference. |
System.Int32 | index | The starting index within this collection. |
Returns
Type | Description |
---|---|
System.Int32 | The zero-based index of the first occurrence of |
Insert(Int32, T)
Inserts an element into the List at the specified index.
Declaration
public virtual void Insert(int index, T item)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | The zero-based index at which item should be inserted. |
T | item | The object to insert. The value can be a null reference. |
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException | Thrown if the specified index is out of range. |
Remove(T)
Removes an element from this collection.
Declaration
public virtual bool Remove(T item)
Parameters
Type | Name | Description |
---|---|---|
T | item | The element to remove. |
Returns
Type | Description |
---|---|
System.Boolean | True if element was successfully removed; otherwise, false. |
RemoveAt(Int32)
Removes the element at the specified index.
Declaration
public virtual void RemoveAt(int index)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | The zero-based index of the element to remove. |
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException | Thrown if the specified index is out of range. |
Sort()
Sorts the entire collection using the System.Collections.Generic.Comparer`1.Default comparer.
Declaration
public void Sort()
Sort(IComparer<T>)
Sorts the entire collection using the specified System.Collections.Generic.Comparer`1 comparer.
Declaration
public void Sort(IComparer<T> comparer)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IComparer<T> | comparer | The System.Collections.Generic.IComparer<T> implementation to use when comparing elements. |
Sort(Comparison<T>)
Sorts the entire collection using the specified System.Comparison<T> delegate.
Declaration
public void Sort(Comparison<T> comparison)
Parameters
Type | Name | Description |
---|---|---|
System.Comparison<T> | comparison | The System.Comparison<T> delegate. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | Thrown if the specified comparison is a null reference. |
Sort(Int32, Int32, IComparer<T>)
Sorts the range of this collection using the specified System.Collections.Generic.Comparer`1 comparer.
Declaration
public void Sort(int index, int count, IComparer<T> comparer)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | The zero-based starting index of the range to sort. |
System.Int32 | count | The length of the range to sort. |
System.Collections.Generic.IComparer<T> | comparer | The System.Collections.Generic.Comparer`1 to use. |
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException | Thrown if the specified index or count is out of range. |
ToArray()
Copies elements of this collection to a new array.
Declaration
public T[] ToArray()
Returns
Type | Description |
---|---|
T[] | An array that contains all elements in this collection. |
Explicit Interface Implementations
IEnumerable.GetEnumerator()
Gets the System.Collections.IEnumerator interface that can be used to iterate through this collection.
Declaration
IEnumerator IEnumerable.GetEnumerator()
Returns
Type | Description |
---|---|
System.Collections.IEnumerator | The System.Collections.IEnumerator interface. |