Class RingList<T>
A ring list with a specified size. Adding more elements to the list over its size will silently drop older elements.
public class RingList<T> : IReadOnlyList<T>, IReadOnlyCollection<T>, ICollection<T>, IEnumerable<T>, IEnumerable
Type Parameters
T
The type of objects in the list.
- Inheritance
-
RingList<T>
- Implements
-
ICollection<T>IEnumerable<T>
- Inherited Members
Constructors
RingList(int)
Create a new ring list with the specified capacity
.
public RingList(int capacity)
Parameters
capacity
intMaximum capacity of the ring list.
Properties
Capacity
Maximum number of element the list can contain at the same time.
public int Capacity { get; }
Property Value
Count
Number of elements in the list.
public int Count { get; }
Property Value
IsReadOnly
Is the list read-only (no, it's not).
public bool IsReadOnly { get; }
Property Value
this[int]
Gets or sets the element at the specified index.
public T this[int index] { get; set; }
Parameters
index
intThe zero-based index of the element to get or set.
Property Value
- T
The element at the specified index.
Exceptions
- IndexOutOfRangeException
Thrown if index is greater than
Count
.
Methods
Add(T)
Add an item to the end of the list. If list is already at maximum capacity, the first element will be silently removed.
public void Add(T item)
Parameters
item
TItem to add to the list.
Clear()
Clear list contents.
public void Clear()
Contains(T)
Determines whether the list contains a specific value.
public bool Contains(T item)
Parameters
item
TThe item to locate in the list.
Returns
- bool
true
if item is found in the list; otherwise,false
.
CopyTo(T[], int)
Copies the elements of the list to an array, starting at a particular array index.
public void CopyTo(T[] array, int arrayIndex)
Parameters
array
T[]The one-dimensional array that is the destination of the elements copied from the list. The array must have zero-based indexing.
arrayIndex
intThe zero-based index in
array
at which copying begins.
GetEnumerator()
Returns an enumerator that iterates through the list elements.
public IEnumerator<T> GetEnumerator()
Returns
- IEnumerator<T>
An enumerator that can be used to iterate through the list elements.
Remove(T)
Unsupported operation.
public bool Remove(T item)
Parameters
item
TThe item that would be removed from the list if this operation was supported.
Returns
- bool
Never returns anything, always throws an exception.
Exceptions
- InvalidOperationException
This exception is always thrown.