Class SortedList<TKey, TValue>
- Namespace
- Stride.Core.Collections
- Assembly
- Stride.Core.dll
Represents a collection of associated keys and values that are sorted by the keys and are accessible by key and by index.
public class SortedList<TKey, TValue> : IDictionary<TKey, TValue>, ICollection<KeyValuePair<TKey, TValue>>, IEnumerable<KeyValuePair<TKey, TValue>>, IDictionary, ICollection, IEnumerable
Type Parameters
TKeyTValue
- Inheritance
-
objectSortedList<TKey, TValue>
- Implements
-
IDictionary<TKey, TValue>ICollection<KeyValuePair<TKey, TValue>>IEnumerable<KeyValuePair<TKey, TValue>>
- Extension Methods
Constructors
SortedList()
public SortedList()
SortedList(IComparer<TKey>)
public SortedList(IComparer<TKey> comparer)
Parameters
comparerIComparer<TKey>
SortedList(IDictionary<TKey, TValue>)
public SortedList(IDictionary<TKey, TValue> dictionary)
Parameters
dictionaryIDictionary<TKey, TValue>
SortedList(IDictionary<TKey, TValue>, IComparer<TKey>)
public SortedList(IDictionary<TKey, TValue> dictionary, IComparer<TKey> comparer)
Parameters
dictionaryIDictionary<TKey, TValue>comparerIComparer<TKey>
SortedList(int)
public SortedList(int capacity)
Parameters
capacityint
SortedList(int, IComparer<TKey>)
public SortedList(int capacity, IComparer<TKey> comparer)
Parameters
Properties
Capacity
public int Capacity { get; set; }
Property Value
Comparer
public IComparer<TKey> Comparer { get; }
Property Value
- IComparer<TKey>
Count
Gets the number of elements contained in the ICollection<T>.
public int Count { get; }
Property Value
- int
The number of elements contained in the ICollection<T>.
this[TKey]
Gets or sets the element with the specified key.
public TValue this[TKey key] { get; set; }
Parameters
keyTKeyThe key of the element to get or set.
Property Value
- TValue
The element with the specified key.
Exceptions
- ArgumentNullException
keyis null.- KeyNotFoundException
The property is retrieved and
keyis not found.- NotSupportedException
The property is set and the IDictionary<TKey, TValue> is read-only.
Keys
public IList<TKey> Keys { get; }
Property Value
- IList<TKey>
Values
public IList<TValue> Values { get; }
Property Value
- IList<TValue>
Methods
Add(TKey, TValue)
Adds an element with the provided key and value to the IDictionary<TKey, TValue>.
public void Add(TKey key, TValue value)
Parameters
keyTKeyThe object to use as the key of the element to add.
valueTValueThe object to use as the value of the element to add.
Exceptions
- ArgumentNullException
keyis null.- ArgumentException
An element with the same key already exists in the IDictionary<TKey, TValue>.
- NotSupportedException
The IDictionary<TKey, TValue> is read-only.
Clear()
Removes all elements from the IDictionary object.
public void Clear()
Exceptions
- NotSupportedException
The IDictionary object is read-only.
ContainsKey(TKey)
Determines whether the IDictionary<TKey, TValue> contains an element with the specified key.
public bool ContainsKey(TKey key)
Parameters
keyTKeyThe key to locate in the IDictionary<TKey, TValue>.
Returns
- bool
true if the IDictionary<TKey, TValue> contains an element with the key; otherwise, false.
Exceptions
- ArgumentNullException
keyis null.
ContainsValue(TValue)
public bool ContainsValue(TValue value)
Parameters
valueTValue
Returns
GetEnumerator()
public SortedList<TKey, TValue>.Enumerator GetEnumerator()
Returns
- SortedList<TKey, TValue>.Enumerator
IndexOfKey(TKey)
public int IndexOfKey(TKey key)
Parameters
keyTKey
Returns
IndexOfValue(TValue)
public int IndexOfValue(TValue value)
Parameters
valueTValue
Returns
Remove(TKey)
Removes the element with the specified key from the IDictionary<TKey, TValue>.
public bool Remove(TKey key)
Parameters
keyTKeyThe key of the element to remove.
Returns
- bool
true if the element is successfully removed; otherwise, false. This method also returns false if
keywas not found in the original IDictionary<TKey, TValue>.
Exceptions
- ArgumentNullException
keyis null.- NotSupportedException
The IDictionary<TKey, TValue> is read-only.
RemoveAt(int)
public void RemoveAt(int index)
Parameters
indexint
TrimExcess()
public void TrimExcess()
TryGetValue(TKey, out TValue)
Gets the value associated with the specified key.
public bool TryGetValue(TKey key, out TValue value)
Parameters
keyTKeyThe key whose value to get.
valueTValueWhen this method returns, the value associated with the specified key, if the key is found; otherwise, the default value for the type of the
valueparameter. This parameter is passed uninitialized.
Returns
- bool
true if the object that implements IDictionary<TKey, TValue> contains an element with the specified key; otherwise, false.
Exceptions
- ArgumentNullException
keyis null.