Show / Hide Table of Contents

Class ListBase<T>

ListBase is an abstract class that can be used as a base class for a read-write collection that needs to implement the generic IList<T> and non-generic IList collections. The derived class needs to override the following methods: Count, Clear, Insert, RemoveAt, and the indexer. The implementation of all the other methods in IList<T> and IList are handled by ListBase.

Inheritance
System.Object
CollectionBase<T>
ListBase<T>
Implements
System.Collections.Generic.IList<T>
System.Collections.Generic.ICollection<T>
System.Collections.Generic.IEnumerable<T>
System.Collections.IList
System.Collections.ICollection
System.Collections.IEnumerable
Inherited Members
CollectionBase<T>.ToString()
CollectionBase<T>.ToArray()
CollectionBase<T>.ICollection<T>.IsReadOnly
CollectionBase<T>.Exists(Predicate<T>)
CollectionBase<T>.TrueForAll(Predicate<T>)
CollectionBase<T>.CountWhere(Predicate<T>)
CollectionBase<T>.FindAll(Predicate<T>)
CollectionBase<T>.RemoveAll(Predicate<T>)
CollectionBase<T>.ForEach(Action<T>)
CollectionBase<T>.ConvertAll<TOutput>(Converter<T, TOutput>)
CollectionBase<T>.ICollection.CopyTo(Array, Int32)
CollectionBase<T>.ICollection.IsSynchronized
CollectionBase<T>.ICollection.SyncRoot
CollectionBase<T>.IEnumerable.GetEnumerator()
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
Namespace: Wintellect.PowerCollections
Assembly: CADability.dll
Syntax
[Serializable]
public abstract class ListBase<T> : CollectionBase<T>, IList<T>, ICollection<T>, IEnumerable<T>, IList, ICollection, IEnumerable
Type Parameters
Name Description
T

Constructors

| Improve this Doc View Source

ListBase()

Creates a new ListBase.

Declaration
protected ListBase()

Properties

| Improve this Doc View Source

Count

The property must be overridden by the derived class to return the number of items in the list.

Declaration
public abstract override int Count { get; }
Property Value
Type Description
System.Int32

The number of items in the list.

Overrides
Wintellect.PowerCollections.CollectionBase<T>.Count
| Improve this Doc View Source

Item[Int32]

The indexer must be overridden by the derived class to get and set values of the list at a particular index.

Declaration
public abstract T this[int index] { get; set; }
Parameters
Type Name Description
System.Int32 index

The index in the list to get or set an item at. The first item in the list has index 0, and the last has index Count-1.

Property Value
Type Description
T

The item at the given index.

Exceptions
Type Condition
System.ArgumentOutOfRangeException

index is less than zero or greater than or equal to Count.

Methods

| Improve this Doc View Source

Add(T)

Adds an item to the end of the list. This method is equivalent to calling:

Insert(Count, item)
Declaration
public override void Add(T item)
Parameters
Type Name Description
T item

The item to add to the list.

Overrides
Wintellect.PowerCollections.CollectionBase<T>.Add(T)
| Improve this Doc View Source

AsReadOnly()

Provides a read-only view of this list. The returned IList<T> provides a view of the list that prevents modifications to the list. Use the method to provide access to the list without allowing changes. Since the returned object is just a view, changes to the list will be reflected in the view.

Declaration
public virtual IList<T> AsReadOnly()
Returns
Type Description
System.Collections.Generic.IList<T>

An IList<T> that provides read-only access to the list.

| Improve this Doc View Source

Clear()

This method must be overridden by the derived class to empty the list of all items.

Declaration
public abstract override void Clear()
Overrides
Wintellect.PowerCollections.CollectionBase<T>.Clear()
| Improve this Doc View Source

Contains(T)

Determines if the list contains any item that compares equal to item. The implementation simply checks whether IndexOf(item) returns a non-negative value.

Declaration
public override bool Contains(T item)
Parameters
Type Name Description
T item

The item to search for.

Returns
Type Description
System.Boolean

True if the list contains an item that compares equal to item.

Overrides
Wintellect.PowerCollections.CollectionBase<T>.Contains(T)
Remarks

Equality in the list is determined by the default sense of equality for T. If T implements IComparable<T>, the Equals method of that interface is used to determine equality. Otherwise, Object.Equals is used to determine equality.

| Improve this Doc View Source

CopyTo(T[])

Copies all the items in the list, in order, to array, starting at index 0.

Declaration
public virtual void CopyTo(T[] array)
Parameters
Type Name Description
T[] array

The array to copy to. This array must have a size that is greater than or equal to Count.

| Improve this Doc View Source

CopyTo(T[], Int32)

Copies all the items in the list, in order, to array, starting at arrayIndex.

Declaration
public override void CopyTo(T[] array, int arrayIndex)
Parameters
Type Name Description
T[] array

The array to copy to. This array must have a size that is greater than or equal to Count + arrayIndex.

System.Int32 arrayIndex

The starting index in array to copy to.

Overrides
Wintellect.PowerCollections.CollectionBase<T>.CopyTo(T[], System.Int32)
| Improve this Doc View Source

CopyTo(Int32, T[], Int32, Int32)

Copies a range of elements from the list to array, starting at arrayIndex.

Declaration
public virtual void CopyTo(int index, T[] array, int arrayIndex, int count)
Parameters
Type Name Description
System.Int32 index

The starting index in the source list of the range to copy.

T[] array

The array to copy to. This array must have a size that is greater than or equal to Count + arrayIndex.

System.Int32 arrayIndex

The starting index in array to copy to.

System.Int32 count

The number of items to copy.

| Improve this Doc View Source

Find(Predicate<T>)

Finds the first item in the list that satisfies the condition defined by predicate. If no item matches the condition, than the default value for T (null or all-zero) is returned.

Declaration
public virtual T Find(Predicate<T> predicate)
Parameters
Type Name Description
System.Predicate<T> predicate

A delegate that defined the condition to check for.

Returns
Type Description
T

The first item that satisfies the condition predicate. If no item satisfies that condition, the default value for T is returned.

Remarks

If the default value for T (null or all-zero) matches the condition defined by predicate, and the list might contain the default value, then it is impossible to distinguish the different between finding the default value and not finding any item. To distinguish these cases, use TryFind(Predicate<T>, out T).

See Also
TryFind(Predicate<T>, out T)
| Improve this Doc View Source

FindIndex(Int32, Int32, Predicate<T>)

Finds the index of the first item, in the range of count items starting from index, that satisfies the condition defined by predicate. If no item matches the condition, -1 is returned.

Declaration
public virtual int FindIndex(int index, int count, Predicate<T> predicate)
Parameters
Type Name Description
System.Int32 index

The starting index of the range to check.

System.Int32 count

The number of items in range to check.

System.Predicate<T> predicate

A delegate that defined the condition to check for.

Returns
Type Description
System.Int32

The index of the first item in the given range that satisfies the condition predicate. If no item satisfies that condition, -1 is returned.

| Improve this Doc View Source

FindIndex(Int32, Predicate<T>)

Finds the index of the first item, in the range of items extending from index to the end, that satisfies the condition defined by predicate. If no item matches the condition, -1 is returned.

Declaration
public virtual int FindIndex(int index, Predicate<T> predicate)
Parameters
Type Name Description
System.Int32 index

The starting index of the range to check.

System.Predicate<T> predicate

A delegate that defined the condition to check for.

Returns
Type Description
System.Int32

The index of the first item in the given range that satisfies the condition predicate. If no item satisfies that condition, -1 is returned.

| Improve this Doc View Source

FindIndex(Predicate<T>)

Finds the index of the first item in the list that satisfies the condition defined by predicate. If no item matches the condition, -1 is returned.

Declaration
public virtual int FindIndex(Predicate<T> predicate)
Parameters
Type Name Description
System.Predicate<T> predicate

A delegate that defined the condition to check for.

Returns
Type Description
System.Int32

The index of the first item that satisfies the condition predicate. If no item satisfies that condition, -1 is returned.

| Improve this Doc View Source

FindLast(Predicate<T>)

Finds the last item in the list that satisfies the condition defined by predicate. If no item matches the condition, than the default value for T (null or all-zero) is returned.

Declaration
public virtual T FindLast(Predicate<T> predicate)
Parameters
Type Name Description
System.Predicate<T> predicate

A delegate that defined the condition to check for.

Returns
Type Description
T

The last item that satisfies the condition predicate. If no item satisfies that condition, the default value for T is returned.

Remarks

If the default value for T (null or all-zero) matches the condition defined by predicate, and the list might contain the default value, then it is impossible to distinguish the different between finding the default value and not finding any item. To distinguish these cases, use TryFindLast(Predicate<T>, out T).

See Also
TryFindLast(Predicate<T>, out T)
| Improve this Doc View Source

FindLastIndex(Int32, Int32, Predicate<T>)

Finds the index of the last item, in the range of count items ending at index, that satisfies the condition defined by predicate. If no item matches the condition, -1 is returned.

Declaration
public virtual int FindLastIndex(int index, int count, Predicate<T> predicate)
Parameters
Type Name Description
System.Int32 index

The ending index of the range to check.

System.Int32 count

The number of items in range to check.

System.Predicate<T> predicate

A delegate that defined the condition to check for.

Returns
Type Description
System.Int32

The index of the last item in the given range that satisfies the condition predicate. If no item satisfies that condition, -1 is returned.

| Improve this Doc View Source

FindLastIndex(Int32, Predicate<T>)

Finds the index of the last item, in the range of items extending from the beginning of the list to index, that satisfies the condition defined by predicate. If no item matches the condition, -1 is returned.

Declaration
public virtual int FindLastIndex(int index, Predicate<T> predicate)
Parameters
Type Name Description
System.Int32 index

The ending index of the range to check.

System.Predicate<T> predicate

A delegate that defined the condition to check for.

Returns
Type Description
System.Int32

The index of the last item in the given range that satisfies the condition predicate. If no item satisfies that condition, -1 is returned.

| Improve this Doc View Source

FindLastIndex(Predicate<T>)

Finds the index of the last item in the list that satisfies the condition defined by predicate. If no item matches the condition, -1 is returned.

Declaration
public virtual int FindLastIndex(Predicate<T> predicate)
Parameters
Type Name Description
System.Predicate<T> predicate

A delegate that defined the condition to check for.

Returns
Type Description
System.Int32

The index of the last item that satisfies the condition predicate. If no item satisfies that condition, -1 is returned.

| Improve this Doc View Source

GetEnumerator()

Enumerates all of the items in the list, in order. The item at index 0 is enumerated first, then the item at index 1, and so on.

Declaration
public override IEnumerator<T> GetEnumerator()
Returns
Type Description
System.Collections.Generic.IEnumerator<T>

An IEnumerator<T> that enumerates all the items in the list.

Overrides
Wintellect.PowerCollections.CollectionBase<T>.GetEnumerator()
Remarks

The enumerator does not check for changes made to the structure of the list. Thus, changes to the list during enumeration may cause incorrect enumeration or out of range exceptions. Consider overriding this method and adding checks for structural changes.

| Improve this Doc View Source

IndexOf(T)

Finds the index of the first item in the list that is equal to item.

Declaration
public virtual int IndexOf(T item)
Parameters
Type Name Description
T item

The item to search fror.

Returns
Type Description
System.Int32

The index of the first item in the list that that is equal to item. If no item is equal to item, -1 is returned.

Remarks

The default implementation of equality for type T is used in the search. This is the equality defined by IComparable<T> or object.Equals.

| Improve this Doc View Source

IndexOf(T, Int32)

Finds the index of the first item, in the range of items extending from index to the end,
that is equal to item.

Declaration
public virtual int IndexOf(T item, int index)
Parameters
Type Name Description
T item

The item to search fror.

System.Int32 index

The starting index of the range to check.

Returns
Type Description
System.Int32

The index of the first item in the given range that that is equal to item. If no item is equal to item, -1 is returned.

Remarks

The default implementation of equality for type T is used in the search. This is the equality defined by IComparable<T> or object.Equals.

| Improve this Doc View Source

IndexOf(T, Int32, Int32)

Finds the index of the first item, in the range of count items starting from index,
that is equal to item.

Declaration
public virtual int IndexOf(T item, int index, int count)
Parameters
Type Name Description
T item

The item to search fror.

System.Int32 index

The starting index of the range to check.

System.Int32 count

The number of items in range to check.

Returns
Type Description
System.Int32

The index of the first item in the given range that that is equal to item. If no item is equal to item, -1 is returned.

Remarks

The default implementation of equality for type T is used in the search. This is the equality defined by IComparable<T> or object.Equals.

| Improve this Doc View Source

Insert(Int32, T)

This method must be overridden by the derived class to insert a new item at the given index.

Declaration
public abstract void Insert(int index, T item)
Parameters
Type Name Description
System.Int32 index

The index in the list to insert the item at. After the insertion, the inserted item is located at this index. The first item in the list has index 0.

T item

The item to insert at the given index.

Exceptions
Type Condition
System.ArgumentOutOfRangeException

index is less than zero or greater than Count.

| Improve this Doc View Source

LastIndexOf(T)

Finds the index of the last item in the list that is equal to item.

Declaration
public virtual int LastIndexOf(T item)
Parameters
Type Name Description
T item

The item to search fror.

Returns
Type Description
System.Int32

The index of the last item in the list that that is equal to item. If no item is equal to item, -1 is returned.

Remarks

The default implementation of equality for type T is used in the search. This is the equality defined by IComparable<T> or object.Equals.

| Improve this Doc View Source

LastIndexOf(T, Int32)

Finds the index of the last item, in the range of items extending from the beginning of the list to index, that is equal to item.

Declaration
public virtual int LastIndexOf(T item, int index)
Parameters
Type Name Description
T item

The item to search fror.

System.Int32 index

The ending index of the range to check.

Returns
Type Description
System.Int32

The index of the last item in the given range that that is equal to item. If no item is equal to item, -1 is returned.

Remarks

The default implementation of equality for type T is used in the search. This is the equality defined by IComparable<T> or object.Equals.

| Improve this Doc View Source

LastIndexOf(T, Int32, Int32)

Finds the index of the last item, in the range of count items ending at index, that is equal to item.

Declaration
public virtual int LastIndexOf(T item, int index, int count)
Parameters
Type Name Description
T item

The item to search for.

System.Int32 index

The ending index of the range to check.

System.Int32 count

The number of items in range to check.

Returns
Type Description
System.Int32

The index of the last item in the given range that that is equal to item. If no item is equal to item, -1 is returned.

Remarks

The default implementation of equality for type T is used in the search. This is the equality defined by IComparable<T> or object.Equals.

| Improve this Doc View Source

Range(Int32, Int32)

Returns a view onto a sub-range of this list. Items are not copied; the returned IList<T> is simply a different view onto the same underlying items. Changes to this list are reflected in the view, and vice versa. Insertions and deletions in the view change the size of the view, but insertions and deletions in the underlying list do not.

Declaration
public virtual IList<T> Range(int start, int count)
Parameters
Type Name Description
System.Int32 start

The starting index of the view.

System.Int32 count

The number of items in the view.

Returns
Type Description
System.Collections.Generic.IList<T>

A list that is a view onto the given sub-part of this list.

Remarks

This method can be used to apply an algorithm to a portion of a list. For example:

Algorithms.ReverseInPlace(deque.Range(3, 6))
will reverse the 6 items beginning at index 3.
Exceptions
Type Condition
System.ArgumentOutOfRangeException

start or count is negative.

System.ArgumentOutOfRangeException

start + count is greater than the size of the list.

| Improve this Doc View Source

Remove(T)

Searches the list for the first item that compares equal to item. If one is found, it is removed. Otherwise, the list is unchanged.

Declaration
public override bool Remove(T item)
Parameters
Type Name Description
T item

The item to remove from the list.

Returns
Type Description
System.Boolean

True if an item was found and removed that compared equal to item. False if no such item was in the list.

Overrides
Wintellect.PowerCollections.CollectionBase<T>.Remove(T)
Remarks

Equality in the list is determined by the default sense of equality for T. If T implements IComparable<T>, the Equals method of that interface is used to determine equality. Otherwise, Object.Equals is used to determine equality.

| Improve this Doc View Source

RemoveAt(Int32)

This method must be overridden by the derived class to remove the item at the given index.

Declaration
public abstract void RemoveAt(int index)
Parameters
Type Name Description
System.Int32 index

The index in the list to remove the item at. The first item in the list has index 0.

Exceptions
Type Condition
System.ArgumentOutOfRangeException

index is less than zero or greater than or equal to Count.

| Improve this Doc View Source

TryFind(Predicate<T>, out T)

Finds the first item in the list that satisfies the condition defined by predicate.

Declaration
public virtual bool TryFind(Predicate<T> predicate, out T foundItem)
Parameters
Type Name Description
System.Predicate<T> predicate

A delegate that defines the condition to check for.

T foundItem

If true is returned, this parameter receives the first item in the list that satifies the condition defined by predicate.

Returns
Type Description
System.Boolean

True if an item that satisfies the condition predicate was found. False if no item in the list satisfies that condition.

| Improve this Doc View Source

TryFindLast(Predicate<T>, out T)

Finds the last item in the list that satisfies the condition defined by predicate.

Declaration
public virtual bool TryFindLast(Predicate<T> predicate, out T foundItem)
Parameters
Type Name Description
System.Predicate<T> predicate

A delegate that defines the condition to check for.

T foundItem

If true is returned, this parameter receives the last item in the list that satifies the condition defined by predicate.

Returns
Type Description
System.Boolean

True if an item that satisfies the condition predicate was found. False if no item in the list satisfies that condition.

Explicit Interface Implementations

| Improve this Doc View Source

IList.Add(Object)

Adds an item to the end of the list. This method is equivalent to calling:

Insert(Count, item)
Declaration
int IList.Add(object value)
Parameters
Type Name Description
System.Object value

The item to add to the list.

Returns
Type Description
System.Int32
Exceptions
Type Condition
System.ArgumentException

value cannot be converted to T.

| Improve this Doc View Source

IList.Clear()

Removes all the items from the list, resulting in an empty list.

Declaration
void IList.Clear()
| Improve this Doc View Source

IList.Contains(Object)

Determines if the list contains any item that compares equal to value.

Declaration
bool IList.Contains(object value)
Parameters
Type Name Description
System.Object value

The item to search for.

Returns
Type Description
System.Boolean
Remarks

Equality in the list is determined by the default sense of equality for T. If T implements IComparable<T>, the Equals method of that interface is used to determine equality. Otherwise, Object.Equals is used to determine equality.

| Improve this Doc View Source

IList.IndexOf(Object)

Find the first occurrence of an item equal to value in the list, and returns the index of that item.

Declaration
int IList.IndexOf(object value)
Parameters
Type Name Description
System.Object value

The item to search for.

Returns
Type Description
System.Int32

The index of value, or -1 if no item in the list compares equal to value.

Remarks

Equality in the list is determined by the default sense of equality for T. If T implements IComparable<T>, the Equals method of that interface is used to determine equality. Otherwise, Object.Equals is used to determine equality.

| Improve this Doc View Source

IList.Insert(Int32, Object)

Insert a new item at the given index.

Declaration
void IList.Insert(int index, object value)
Parameters
Type Name Description
System.Int32 index

The index in the list to insert the item at. After the insertion, the inserted item is located at this index. The first item in the list has index 0.

System.Object value

The item to insert at the given index.

Exceptions
Type Condition
System.ArgumentOutOfRangeException

index is less than zero or greater than Count.

System.ArgumentException

value cannot be converted to T.

| Improve this Doc View Source

IList.IsFixedSize

Returns whether the list is a fixed size. This implementation always returns false.

Declaration
bool IList.IsFixedSize { get; }
Returns
Type Description
System.Boolean

Alway false, indicating that the list is not fixed size.

| Improve this Doc View Source

IList.IsReadOnly

Returns whether the list is read only. This implementation returns the value from ICollection<T>.IsReadOnly, which is by default, false.

Declaration
bool IList.IsReadOnly { get; }
Returns
Type Description
System.Boolean

By default, false, indicating that the list is not read only.

| Improve this Doc View Source

IList.Item[Int32]

Gets or sets the value at a particular index in the list.

Declaration
object IList.this[int index] { get; set; }
Parameters
Type Name Description
System.Int32 index

The index in the list to get or set an item at. The first item in the list has index 0, and the last has index Count-1.

Returns
Type Description
System.Object

The item at the given index.

Exceptions
Type Condition
System.ArgumentOutOfRangeException

index is less than zero or greater than or equal to Count.

System.ArgumentException

value cannot be converted to T.

| Improve this Doc View Source

IList.Remove(Object)

Searches the list for the first item that compares equal to value. If one is found, it is removed. Otherwise, the list is unchanged.

Declaration
void IList.Remove(object value)
Parameters
Type Name Description
System.Object value

The item to remove from the list.

Remarks

Equality in the list is determined by the default sense of equality for T. If T implements IComparable<T>, the Equals method of that interface is used to determine equality. Otherwise, Object.Equals is used to determine equality.

Exceptions
Type Condition
System.ArgumentException

value cannot be converted to T.

| Improve this Doc View Source

IList.RemoveAt(Int32)

Removes the item at the given index.

Declaration
void IList.RemoveAt(int index)
Parameters
Type Name Description
System.Int32 index

The index in the list to remove the item at. The first item in the list has index 0.

Exceptions
Type Condition
System.ArgumentOutOfRangeException

index is less than zero or greater than or equal to Count.

Implements

System.Collections.Generic.IList<T>
System.Collections.Generic.ICollection<T>
System.Collections.Generic.IEnumerable<T>
System.Collections.IList
System.Collections.ICollection
System.Collections.IEnumerable
  • Improve this Doc
  • View Source
In This Article
Back to top Generated by DocFX