Class OrderedDictionary<TKey, TVal>
- Namespace
- Examine
- Assembly
- Examine.Core.dll
An implementation of a generic ordered dictionary
public class OrderedDictionary<TKey, TVal> : KeyedCollection<TKey, KeyValuePair<TKey, TVal>>, IList<KeyValuePair<TKey, TVal>>, IReadOnlyList<KeyValuePair<TKey, TVal>>, IList, ICollection, IDictionary<TKey, TVal>, ICollection<KeyValuePair<TKey, TVal>>, IReadOnlyDictionary<TKey, TVal>, IReadOnlyCollection<KeyValuePair<TKey, TVal>>, IEnumerable<KeyValuePair<TKey, TVal>>, IEnumerable where TKey : notnull
Type Parameters
TKey
TVal
- Inheritance
-
Collection<KeyValuePair<TKey, TVal>>KeyedCollection<TKey, KeyValuePair<TKey, TVal>>OrderedDictionary<TKey, TVal>
- Implements
-
IList<KeyValuePair<TKey, TVal>>IReadOnlyList<KeyValuePair<TKey, TVal>>IDictionary<TKey, TVal>ICollection<KeyValuePair<TKey, TVal>>IReadOnlyDictionary<TKey, TVal>IReadOnlyCollection<KeyValuePair<TKey, TVal>>IEnumerable<KeyValuePair<TKey, TVal>>
- Inherited Members
Constructors
OrderedDictionary()
Initializes a new instance of the KeyedCollection<TKey, TItem> class that uses the default equality comparer.
public OrderedDictionary()
OrderedDictionary(IEqualityComparer<TKey>)
Initializes a new instance of the KeyedCollection<TKey, TItem> class that uses the specified equality comparer.
public OrderedDictionary(IEqualityComparer<TKey> comparer)
Parameters
comparer
IEqualityComparer<TKey>The implementation of the IEqualityComparer<T> generic interface to use when comparing keys, or null to use the default equality comparer for the type of the key, obtained from Default.
Properties
Keys
Gets an ICollection<T> containing the keys of the IDictionary<TKey, TValue>.
public ICollection<TKey> Keys { get; }
Property Value
- ICollection<TKey>
An ICollection<T> containing the keys of the object that implements IDictionary<TKey, TValue>.
Values
Gets an ICollection<T> containing the values in the IDictionary<TKey, TValue>.
public ICollection<TVal> Values { get; }
Property Value
- ICollection<TVal>
An ICollection<T> containing the values in the object that implements IDictionary<TKey, TValue>.
Methods
Add(TKey, TVal)
Adds an element with the provided key and value to the IDictionary<TKey, TValue>.
public void Add(TKey key, TVal value)
Parameters
key
TKeyThe object to use as the key of the element to add.
value
TValThe object to use as the value of the element to add.
Exceptions
- ArgumentNullException
key
is null.- ArgumentException
An element with the same key already exists in the IDictionary<TKey, TValue>.
- NotSupportedException
The IDictionary<TKey, TValue> is read-only.
ContainsKey(TKey)
Determines whether the IDictionary<TKey, TValue> contains an element with the specified key.
public bool ContainsKey(TKey key)
Parameters
key
TKeyThe 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
key
is null.
GetItem(int)
public TVal GetItem(int index)
Parameters
index
int
Returns
- TVal
GetKeyForItem(KeyValuePair<TKey, TVal>)
When implemented in a derived class, extracts the key from the specified element.
protected override TKey GetKeyForItem(KeyValuePair<TKey, TVal> item)
Parameters
item
KeyValuePair<TKey, TVal>The element from which to extract the key.
Returns
- TKey
The key for the specified element.
IndexOf(TKey)
public int IndexOf(TKey key)
Parameters
key
TKey
Returns
TryGetValue(TKey, out TVal)
Gets the value associated with the specified key.
public bool TryGetValue(TKey key, out TVal value)
Parameters
key
TKeyThe key whose value to get.
value
TValWhen this method returns, the value associated with the specified key, if the key is found; otherwise, the default value for the type of the
value
parameter. 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
key
is null.