方法的重载
方法名字相同,参数不同,就构成了方法的重载
示例:
using System; namespace 练习 { class Program { static void Main(string[] args) { int sum = Program.M(1, 3); string str = Program.M("春", "哥"); Console.WriteLine(sum); Console.WriteLine(str); } //两个方法名字都叫M,但参数不一样 //名字相同,参数不同,就构成了方法的重载 public static int M(int n1, int n2) { return n1 + n2; } public static string M(string s1, string s2) { return s1 + s2; } } }

浙公网安备 33010602011771号