using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Demo
{
class Program
{
static int MaxValue(int[] intArray)
{
int maxVal = intArray[0];
for (int i = 1; i < intArray.Length; i++)
{
if (intArray[i] > maxVal)
{
maxVal = intArray[i];
}
}
return maxVal;
}
static double MaxValue(double[] doubleArray)
{
double maxVal = doubleArray[0];
for (int i = 1; i < doubleArray.Length; i++)
{
if (doubleArray[i] > maxVal)
{
maxVal = doubleArray[i];
}
}
return maxVal;
}
static void Main(string[] args)
{
int[] myArray = { 1, 3, 5, 8, 2, 10, 9, 100, 40 };
int maxVal = MaxValue(myArray);
Console.WriteLine("最大值为:{0}", maxVal);
double[] doubleArray = { 1, 3, 5, 8, 2, 10, 9.2, 100.11, 40 };
double maxDoubleVal = MaxValue(doubleArray);
Console.WriteLine("最大值为:{0}", maxDoubleVal);
Console.ReadKey();
}
}
}
本文转自TBHacker博客园博客,原文链接:http://www.cnblogs.com/jiqing9006/p/6748280.html,如需转载请自行联系原作者