NamedListWithDefault<T>

public sealed class NamedListWithDefault<T>
A list of named values with one unnamed value always available.
T

Constructors

NamedListWithDefault

#
Create a new list with an unnamed default value.
public NamedListWithDefault(
T
unnamedDefault,
Initial default value.
comparison
Comparison to use for names.
)

Properties

Count

#
Gets the number of values, not including the unnamed value.
public int Count { get; }

Named

#
Gets the underlying dictionary of named values.
public IDictionary<string, T> Named { get; }

Names

#
Iterate over all names.
public IEnumerable<string> Names { get; }

Unnamed

#
Gets or sets the unnamed default.
public T Unnamed { get; set; }

Indexers

this[]

#
Gets the indexed value. Zero represents the unnamed value, higher integers index the named list.
public (string name, T value) this[
index
] { get; }

this[]

#
Gets or sets the named value. If name is null or empty, the unnamed value is returned or set. If the name conflicts with an existing name, the old value will be overwritten.
public T this[
name
] { get; set; }

Methods

TryGet

#
Try and retrieve one of the values.
public bool TryGet(
name,
out T
value
)

TryRemove

#
Try and remove the named value. Note that the unnamed value cannot be removed, you can only change the value it has.
public bool TryRemove(
name
)