最大整数值查找表&LT; INT&GT; [英] Maximum integer value find in list<int>
本文介绍了最大整数值查找表&LT; INT&GT;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个列表与LT; INT&GT;
与几个元素。我知道我能得到的所有值,如果我通过它遍历与的foreach
,但我只是想在列表中的最大int值。
变种L =新的List&LT; INT&GT;(){1,3,2};
解决方案
假设.NET Framework 3.5或更高版本:
变种L =新的List&LT; INT&GT;(){1,3,2};
变种最大= l.Max();
Console.WriteLine(最大); //输出3
很多很多的冷却时间,储户像这些在可枚举类的。
I have a List<int>
with several elements. I know I can get all the values if I iterate through it with foreach
, but I just want the maximum int value in the list.
var l = new List<int>() { 1, 3, 2 };
解决方案
Assuming .NET Framework 3.5 or greater:
var l = new List<int>() { 1, 3, 2 };
var max = l.Max();
Console.WriteLine(max); // prints 3
Lots and lots of cool time-savers like these in the Enumerable class.
这篇关于最大整数值查找表&LT; INT&GT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文