Since you can access the SortedList using index (see the Notes section) , I would recommend using the following:
var index = mList.IndexOfKey(key); var first = mList.Values[index]; var second = mList.Values[index + 1];
This will work in the same O(log n) as one search.
The LINQ method is also used here:
var items = mList.SkipWhile(m => m.Key != key).Select(m => m.Value).Take(2).ToList();
It will be only once. It will execute in O(n) .
Scott Rippey
source share