Using SortedDictionary - Get Next Value

I use SortedDictionary to store values ​​sorted by integers.

I need to get the following value after a certain existing integer. I would prefer to work with an enumerator, but there is no GetEnumerator(Key k) or similar function.

 SortedDictionary<int, MyClass> _dict; void GetNextValue(int start, out MyClass ret) { } 
+4
source share
1 answer

As for the link added by Ani, in this case it would be something like this:

 ret = source.SkipWhile(pair => pair.Key <= start).First().Value; 

or perhaps (to use try-style)

 using(var iter = source.GetEnumerator()) { while(iter.MoveNext()) { if(iter.Current.Key > start) { ret = iter.Current.Value; return true; } } ret = null; return false; } 
+1
source

Source: https://habr.com/ru/post/1339351/


All Articles