获取字典中的最大关键 [英] Get the largest key in a dictionary

查看:123
本文介绍了获取字典中的最大关键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有那些按键整数字典。我想获得最大的关键。我不跟踪钥匙所以他们可能是连续的(如1,2,3,4,5,6),但可能会跳过(1,3,4,5),但我怀疑有什么差别。

I have a dictionary with keys that are ints. I would like to get the largest key. I don't keep track of keys so they might be consecutive (e.g. 1,2,3,4,5,6) but might skip (1,3,4,5) although I doubt that makes any difference.

我只是用二进制搜索还是有方法?至于我看到你很难击败的二进制搜索这样一个简单的任务 - 也许你可以减少一半。

Do I just use a binary search or is there a method? As far as I see you can hardly beat binary search for such a simple task - maybe you can halve it.

推荐答案

如果你有LINQ提供,你应该能够做到:

If you have LINQ available, you should be able to do:

myDictionary.Keys.Max();

这篇关于获取字典中的最大关键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆