C#方法重载
方法重载
public class Penson {
//使用方法重载可以使用方法调用更加方便——方法名一样的多个方法
//方法名必须一样
//1.方法中的参数列表必须不同
//2.方法中的参数的个数不同
//在方法重载中,与返回值类型无关
public int sum (int a, int b) {
return a + b;
}
public float sum(float a, float b,float c)
{
return a + b + c;
}
}
class Program
{
static void Main(string[] args)
{
Penson p = new Penson();
Console.WriteLine(p.sum(5,8));
Console.WriteLine(p.sum(5.1f, 8.5f,9.4f));
}
}
}
因为经历,
所以懂得;
因为懂得,
所以珍惜。

浙公网安备 33010602011771号