namespace _052_函數(shù)的重載 {
? ? class Program {
? ? ? ? static int MaxValue(params int[] array)
? ? ? ? {
? ? ? ? ? ? Console.WriteLine("int類型的maxvalue被調(diào)用 ");
? ? ? ? ? ? int maxValue = array[0];
? ? ? ? ? ? for (int i = 1; i < array.Length; i++)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? if (array[i] > maxValue)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? maxValue = array[i];
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? return maxValue;
? ? ? ? }
? ? ? ? static double MaxValue(params double[] array)
? ? ? ? {
? ? ? ? ? ? Console.WriteLine("double類型的maxvalue被調(diào)用 ");
? ? ? ? ? ? double maxValue = array[0];
? ? ? ? ? ? for (int i = 1; i < array.Length; i++) {
? ? ? ? ? ? ? ? if (array[i] > maxValue) {
? ? ? ? ? ? ? ? ? ? maxValue = array[i];
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? return maxValue;
? ? ? ? }
? ? ? ? static void Main(string[] args)
? ? ? ? {
? ? ? ? ? ? int res = MaxValue(234, 23, 4);//編譯器會(huì)根據(jù)你傳遞過來的實(shí)參的類型去判定調(diào)用哪一個(gè)函數(shù)
? ? ? ? ? ? double res2 = MaxValue(23.34, 234.5, 234.4);
? ? ? ? ? ? Console.WriteLine(res);
? ? ? ? ? ? Console.WriteLine(res2);
? ? ? ? ? ? Console.ReadKey();
? ? ? ? }
? ? }
}