Struct ListSlim<T>
- Namespace
- LfrlAnvil
- Assembly
- LfrlAnvil.Core.dll
Represents a slim version of a dynamic array of objects.
public struct ListSlim<T>Type Parameters
- T
- Element type. 
- Inherited Members
- Extension Methods
Properties
Capacity
Gets the number of maximum elements that this list can contain without resizing the underlying buffer.
public int Capacity { get; }Property Value
Count
Gets the number of elements contained in this list.
public readonly int Count { get; }Property Value
IsEmpty
Specifies whether or not this list is empty.
public bool IsEmpty { get; }Property Value
this[int]
Gets a reference to an element at the given index.
public ref T this[int index] { get; }Parameters
- indexint
- The zero-based index of the element reference to get. 
Property Value
- T
Exceptions
- ArgumentOutOfRangeException
- When - indexis out of bounds.
Methods
Add(T)
Adds item to the end of this list.
public void Add(T item)Parameters
- itemT
- Item to add. 
AddRange(ReadOnlySpan<T>)
Adds a range of items to the end of this list.
public void AddRange(ReadOnlySpan<T> items)Parameters
- itemsReadOnlySpan<T>
- Items to add. 
Remarks
Does nothing when items are empty.
AsMemory()
Creates a new Memory<T> instance that represents a view of this list.
[Pure]
public Memory<T> AsMemory()Returns
AsSpan()
Creates a new Span<T> instance that represents a view of this list.
[Pure]
public Span<T> AsSpan()Returns
Clear()
Removes all elements from this list.
public void Clear()Create(IEnumerable<T>, int)
Creates a new ListSlim<T> instance that contains all elements from source.
[Pure]
public static ListSlim<T> Create(IEnumerable<T> source, int minCapacity = 0)Parameters
- sourceIEnumerable<T>
- Source collection of elements. 
- minCapacityint
- Minimum initial Capacity of the created list. Equal to 0 by default. 
Returns
- ListSlim<T>
- New ListSlim<T> instance. 
Create(int)
Creates a new empty ListSlim<T> instance.
[Pure]
public static ListSlim<T> Create(int minCapacity = 0)Parameters
Returns
- ListSlim<T>
- New ListSlim<T> instance. 
First()
Returns a reference to the first element.
[Pure]
public ref T First()Returns
- T
- Reference to the first element. 
Remarks
May return an invalid reference, when this list is empty.
GetEnumerator()
Creates a new Span<T>.Enumerator instance for this list.
[Pure]
public Span<T>.Enumerator GetEnumerator()Returns
- Span<T>.Enumerator
- New Span<T>.Enumerator instance. 
InsertAt(int, T)
Adds item at the specified position to this list.
public void InsertAt(int index, T item)Parameters
- indexint
- The zero-based index at which to add the - item.
- itemT
- Item to add. 
Exceptions
- ArgumentOutOfRangeException
- When - indexis out of bounds.
InsertRangeAt(int, ReadOnlySpan<T>)
Adds a range of items at the specified position to this list.
public void InsertRangeAt(int index, ReadOnlySpan<T> items)Parameters
- indexint
- The zero-based index at which to start adding - items.
- itemsReadOnlySpan<T>
- Items to add. 
Remarks
Does nothing when items are empty.
Exceptions
- ArgumentOutOfRangeException
- When - indexis out of bounds.
RemoveAt(int)
Removes an item at the specified position from this list.
public void RemoveAt(int index)Parameters
- indexint
- The zero-based index of an element to be removed. 
Exceptions
- ArgumentOutOfRangeException
- When - indexis out of bounds.
RemoveLast()
Attempts to remove the last item from this list.
public bool RemoveLast()Returns
- bool
- true when list was not empty and last item was removed, otherwise false. 
RemoveLastRange(int)
Attempts to remove a range of last items from this list.
public int RemoveLastRange(int count)Parameters
- countint
- Number of elements to remove. 
Returns
- int
- Actual number of removed elements. 
Remarks
Does nothing, when count is less than or equal to 0.
When count is greater than list's Count,
then clears the list and returns its old Count.
RemoveRangeAt(int, int)
Removes a range of items from this list, starting at the specified position.
public void RemoveRangeAt(int index, int count)Parameters
- indexint
- The zero-based index of the first element to be removed. 
- countint
- Number of elements to remove. 
Remarks
Does nothing, when count is less than or equal to 0.
Exceptions
- ArgumentOutOfRangeException
- When - indexor- countare out of bounds.
ResetCapacity(int)
Attempts to increase or decrease this list's Capacity, while ensuring that all current elements will fit.
public void ResetCapacity(int minCapacity = 0)