I am using SortedDictionary to store values sorted by integer.
I need to get next value after specific existing integer. I would prefer working with enumerator but there is no GetEnumerator(Key k)
or similar function.
SortedDictionary<int, MyClass> _dict;
void GetNextValue(int start, out MyClass ret)
{
}
In C#, SortedDictionary is a generic collection which is used to store the key/value pairs in the sorted form and the sorting is done on the key. SortedDictionary is defined under System. Collection. Generic namespace.
A SortedList object internally maintains two arrays to store the elements of the list; that is, one array for the keys and another array for the associated values. Each element is a key/value pair that can be accessed as a DictionaryEntry object. A key cannot be null , but a value can be.
A SortedList represents a collection of objects stored as key-value pairs that are sorted by the keys.
C# | SortedDictionary. This method is used to check whether the SortedDictionary<TKey, TValue> contains an element with the specified value or not. Syntax: public bool ContainsValue (TValue value); Here, the value is the Value to locate in the SortedDictionary.
With reference to the link that Ani added, in this case it would be something like:
ret = source.SkipWhile(pair => pair.Key <= start).First().Value;
or maybe (to allow a Try
-style usage)
using(var iter = source.GetEnumerator()) {
while(iter.MoveNext()) {
if(iter.Current.Key > start) {
ret = iter.Current.Value;
return true;
}
}
ret = null;
return false;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With