Table of Contents

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

int

Count

Gets the number of elements contained in this list.

public readonly int Count { get; }

Property Value

int

IsEmpty

Specifies whether or not this list is empty.

public bool IsEmpty { get; }

Property Value

bool

this[int]

Gets a reference to an element at the given index.

public ref T this[int index] { get; }

Parameters

index int

The zero-based index of the element reference to get.

Property Value

T

Exceptions

ArgumentOutOfRangeException

When index is out of bounds.

Methods

Add(T)

Adds item to the end of this list.

public void Add(T item)

Parameters

item T

Item to add.

AddRange(ReadOnlySpan<T>)

Adds a range of items to the end of this list.

public void AddRange(ReadOnlySpan<T> items)

Parameters

items ReadOnlySpan<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

Memory<T>

New Memory<T> instance.

AsSpan()

Creates a new Span<T> instance that represents a view of this list.

[Pure]
public Span<T> AsSpan()

Returns

Span<T>

New Span<T> instance.

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

source IEnumerable<T>

Source collection of elements.

minCapacity int

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

minCapacity int

Minimum initial Capacity of the created list. Equal to 0 by default.

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

index int

The zero-based index at which to add the item.

item T

Item to add.

Exceptions

ArgumentOutOfRangeException

When index is 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

index int

The zero-based index at which to start adding items.

items ReadOnlySpan<T>

Items to add.

Remarks

Does nothing when items are empty.

Exceptions

ArgumentOutOfRangeException

When index is out of bounds.

RemoveAt(int)

Removes an item at the specified position from this list.

public void RemoveAt(int index)

Parameters

index int

The zero-based index of an element to be removed.

Exceptions

ArgumentOutOfRangeException

When index is 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

count int

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

index int

The zero-based index of the first element to be removed.

count int

Number of elements to remove.

Remarks

Does nothing, when count is less than or equal to 0.

Exceptions

ArgumentOutOfRangeException

When index or count are 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)

Parameters

minCapacity int

Minimum desired Capacity of this list. Equal to 0 by default.