我陷入了从数组中获取最小值的困境。
每次我运行它时,最小值仍然为零。
我知道索引必须减一,但我只是不知道应该如何将它应用到代码上。
public class Class1 {
int[] numbers = new int[99];
public int Min() { // array gets de value thats on 0
int Min = numbers[0];
foreach(int number in numbers) { // if the number is smaller then 0.
if (number < Min) { // zero is the new number
Min = number;
}
}
return Min;
}
}
您可以轻松地使用 Linq,
使用 System.Linq;
int min = numbers.Min();
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)