简体   繁体   中英

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

I have a dictionary declared as following:

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

How do I get the max value of Item2 of all dictionary values?

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

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

You can use the Max method . Not entirely clear which one of these you're asking for:

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));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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