您现在的位置是:首页 > 电脑 > 

使用SortedDictionary

2025-07-27 15:46:49
使用SortedDictionary - 获取下一个值(Using SortedDictionary - getting next value) 我正在使用SortedDictionary来存储按整数排序的值。 我需要获得特定现有整数后的下一个值。 我宁愿使用枚举器,但没有GetEnumerator(Key k)或类似的函数。 SortedDictio
使用SortedDictionary - 获取下一个值(Using SortedDictionary - getting next value)

我正在使用SortedDictionary来存储按整数排序的值。

我需要获得特定现有整数后的下一个值。 我宁愿使用枚举器,但没有GetEnumerator(Key k)或类似的函数。

SortedDictionary<int, MyClass> _dict; void GetextValue(int start, out MyClass ret) { }

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 GetextValue(int start, out MyClass ret) { }

最满意答案

参考Ani补充的链接,在这种情况下,它会是这样的:

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

或者可能(允许Try式使用)

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

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.Moveext()) { if(iter.Current.Key > start) { ret = iter.Current.Value; return true; } } ret = null; return false; }

#感谢您对电脑配置推荐网 - 最新i3 i5 i7组装电脑配置单推荐报价格的认可,转载请说明来源于"电脑配置推荐网 - 最新i3 i5 i7组装电脑配置单推荐报价格

本文地址:http://www.dnpztj.cn/diannao/50269.html

相关标签:无
上传时间: 2023-04-14 14:39:13
留言与评论(共有 13 条评论)
本站网友 李亚鹏的女儿
28分钟前 发表
但没有GetEnumerator(Key k)或类似的函数
本站网友 pentagon
27分钟前 发表
MyClass> _dict; void GetextValue(int start
本站网友 rogaine
25分钟前 发表
使用SortedDictionary - 获取下一个值(Using SortedDictionary - getting next value) 我正在使用SortedDictionary来存储按整数排序的值
本站网友 回收站不见了
8分钟前 发表
out MyClass ret) { } 最满意答案 参考Ani补充的链接
本站网友 榨菜鲜肉月饼
10分钟前 发表
MyClass> _dict; void GetextValue(int start
本站网友 莲塘二手房出售
15分钟前 发表
在这种情况下
本站网友 皮肤病研究所
7分钟前 发表
使用SortedDictionary - 获取下一个值(Using SortedDictionary - getting next value) 我正在使用SortedDictionary来存储按整数排序的值
本站网友 元隆府邸
23分钟前 发表
ret = source.SkipWhile(pair => pair.Key <= start).First().Value; or maybe (to allow a Try-style usage) using(var iter = source.GetEnumerator()) { while(iter.Moveext()) { if(iter.Current.Key > start) { ret = iter.Current.Value; return true; } } ret = null; return false; }
本站网友 日本民居
3分钟前 发表
我需要获得特定现有整数后的下一个值
本站网友 雷公藤的功效与作用
15分钟前 发表
in this case it would be something like
本站网友 就业难
23分钟前 发表
我宁愿使用枚举器
本站网友 豫园小吃
7分钟前 发表
但没有GetEnumerator(Key k)或类似的函数