using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication8
{
class Program
{
static int MaxValue(params int[] array)
{
int maxValue = array[0];
for (int i = 1; i < array.Length; i++)
{
if (array[i] > maxValue)
{
maxValue = array[i];
Console.WriteLine("喵");
}
}
return maxValue;
}
static double MaxValue(params double[] array)
{
double maxValue = array[0];
for (int i = 1; i < array.Length; i++)
{
if (array[i] > maxValue)
{
maxValue = array[i];
Console.WriteLine("喵");
}
}
return maxValue;
}
static void Main(string[] args)
{
int res = MaxValue(234, 2443, 4444);
double res2 = MaxValue(23.34, 234.5, 293.9);
Console.WriteLine(res);
Console.ReadKey();
}
}
}
我在执行这段C#程序时得到的结果是
喵
喵
喵
喵
4444
也就是说,所有同名函数都执行了,但最后输出的结果确实是我想要的
我的问题是,C#函数重载时,会把每个同名函数都执行一次吗?
谢谢