Cap*_*mic 5 .net c# dictionary
我使用SortedDictionary来存储按整数排序的值.
我需要在特定的现有整数后得到下一个值.我更喜欢使用枚举器,但没有GetEnumerator(Key k)
或类似的功能.
SortedDictionary<int, MyClass> _dict;
void GetNextValue(int start, out MyClass ret)
{
}
Run Code Online (Sandbox Code Playgroud)
参考 Ani 添加的链接,在本例中它将类似于:
ret = source.SkipWhile(pair => pair.Key <= start).First().Value;
Run Code Online (Sandbox Code Playgroud)
或者也许(允许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;
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3950 次 |
最近记录: |