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;
}
/// <summary>
/// 函数重载了
/// </summary>
/// <param name="doubleArray"></param>
/// <returns></returns>
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();
}
}
}