KGy SOFT

CircularSortedListTKey, TValueAsList Property

KGy SOFT Core Libraries Help

Namespace:  KGySoft.Collections
Assembly:  KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 6.0.0
Syntax

public IList<KeyValuePair<TKey, TValue>> AsList { get; }

Property Value

Type: IListKeyValuePairTKey, TValue
Remarks

CircularSortedListTKey, TValue implements both IDictionaryTKey, TValue and IListT interfaces. This means, for example, that two indexers are available for it: IDictionary<TKey,TValue>.Item[TKey] and IList<T>.Item[int]. Latter is implemented as explicit interface implementation to avoid ambiguity when TKey is int, so the CircularSortedListTKey, TValue should be cast to IListT when the list indexer is used. Alternatively, the AsList property can be used to use the indexer (and other members) of IListT interface as it is demonstrated in the example below.

This property is an O(1) operation.

Examples

C#
var coll = new CircularSortedList<int, string> { { 1, "One" }, { 2, "Two" } };
var value = coll[1]; // value contains "One" - same as ((IDictionary<int, string>)coll)[1];
var item = coll.AsList[1]; // item contains KeyValuePair<int, string>(2, "Two") - same as ((IList<KeyValuepair<int, string>>)coll)[1];
See Also

Reference