CircularBuffer<T> Class
A circular buffer (ring buffer) collection that maintains a fixed-size buffer and overwrites old items when full.
public sealed class CircularBuffer<T> : ICollection<T>, IEnumerable<T>, IReadOnlyCollection<T>, IReadOnlyList<T>, IEnumerableType parameters
T
Example
var buffer = new CircularBuffer<int>(3) { AllowOverwrite = true };
buffer.AddLast(1);
buffer.AddLast(2);
buffer.AddLast(3);
Assert.Equal([1, 2, 3], buffer);
buffer.AddLast(4); // overwrites 1
Assert.Equal([2, 3, 4], buffer);Nested types
| Name | Description |
|---|---|
| CircularBuffer<T>.Enumerator |
Constructors
| Name | Description |
|---|---|
| CircularBuffer(int) | Initializes a new instance of the CircularBuffer<T> class with the specified capacity. |
CircularBuffer(int)
CircularBuffer.csInitializes a new instance of the CircularBuffer<T> class with the specified capacity.
public CircularBuffer(int capacity)Parameters
capacityint
Properties
| Name | Description |
|---|---|
| AllowOverwrite | Gets or sets a value indicating whether old items should be overwritten when the buffer is full. |
| Capacity | Gets or sets the maximum number of items the buffer can hold. |
| Count | Gets the current number of items in the buffer. |
| System.Collections.Generic.ICollection<T>.IsReadOnly |
AllowOverwrite
CircularBuffer.csCapacity
CircularBuffer.csCount
CircularBuffer.csSystem.Collections.Generic.ICollection<T>.IsReadOnly
CircularBuffer.csIndexers
| Name | Description |
|---|---|
| this[int] |
this[int]
CircularBuffer.csMethods
AddFirst(T)
CircularBuffer.csAddLast(T)
CircularBuffer.csClear()
CircularBuffer.cspublic void Clear()No documentation is available.
Contains(T)
CircularBuffer.csCopyTo(T[], int)
CircularBuffer.csGetEnumerator()
CircularBuffer.csIndexOf(T)
CircularBuffer.csRemoveFirst()
CircularBuffer.cspublic T RemoveFirst()Returns
T
No documentation is available.
RemoveLast()
CircularBuffer.cspublic T RemoveLast()Returns
T
No documentation is available.