求数组中最大的数的值:
1、数组的max函数:
class Program
{
static void Main(string[] args)
{
int[] array = {1,3,5,2,4,6,7,9,0,8};
int max= GetMax(array);
Console.WriteLine(\"数组中最大的值是{0}\",max);
Console.ReadKey();
}
///
/// 数组中最大的值
/// ///
///
private static int GetMax(int[] array)
{
return array.max();
}
}
2、分支语句:
class Program
{
static void Main(string[] args)
{
int[] array = {1,3,5,2,4,6,7,9,0,8};
int max= GetMax(array);
Console.WriteLine(\"数组中最大的值是{0}\",max);
Console.ReadKey();
}
///
/// 数组中最大的值
/// ///
///
private static int GetMax(int[] array)
{
int max = 0;
for (int i = 0; i
{
max = max > array[i] ? max : array[i];
}
return max;
}
}
本文地址:https://www.stayed.cn/item/26532
转载请注明出处。
本站部分内容来源于网络,如侵犯到您的权益,请 联系我