SortedList<TKey, TValue> IDictionary<TKey, TValue> IndexOfKey; , :
var collection = new SortedList<int, string>();
int k = GetK();
int kIndex = collection.IndexOfKey(k);
int? smallestKeyGreaterThanK = null;
if (collection.Count > kIndex + 1)
smallestKeyGreaterThanK = collection.Keys[kIndex + 1];
MSDN:
; O (log n).
EDIT. , , ( - ), .NET . , "" ; , ( ). , , . :
List<int> keysList = new List<int>(collection.Keys);
int kIndex = keysList.BinarySearch(k);
BinarySearch , , , . MSDN :
List<T>, ; - , , , .
, :
kIndex = kIndex >= 0 ? kIndex : ~kIndex;