繁体   English   中英

在C#中从字典中的元组中获取最大值

[英]Getting the max value out of a tuple in a dictionary in C#

我有一本字典声明如下:

Dictionary<Tuple<long, long>, Tuple<double, long>> dict= new Dictionary<Tuple<long, long>, Tuple<double, long>>(); 

如何获得所有字典值的Item2的最大值?

您可以像下面这样简单地使用Max LINQ方法:

long max = dict.Values.Max(x => x.Item2);

您可以使用Max方法 不清楚您要选择以下哪一项:

var maxKey = dict.Max(x => x.Key.Item2);
var maxValue = dict.Max(x => x.Value.Item2);

var maxEither = Math.Max(dict.Max(x => x.Key.Item2), dict.Max(x => x.Value.Item2));

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM