我有一个这样的双数组。
double[] arr={1.5,10.9,8.9,6.5,10.0};
我怎样才能找出那些数组元素中最大的数
我已经有了基本的逻辑
public double getLargest(double[] arrray)
{
double largest = arrray[0];
for (int i = 1; i < arrray.Length;i++ )
{
if (arrray[i] > largest)
largest = arrray[i];
}
return largest;
}
我要求像 Math.max() 这样的方法;但是 Math.max() 甚至没有得到 I import System.Linq; (可能是我用的framework 2.0的原因)
我用这种方法的任何方式。
最佳答案
您可以使用 Enumerable.Max
方法
Returns the maximum value in a sequence of values.
double[] arr = { 1.5, 10.9, 8.9, 6.5, 10.0 };
Console.WriteLine(arr.Max()); //10.9
这里是一个 demonstration
.
关于c# - 查找双数组中的最大数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20260148/