C#方法的重载
方法的重载
参数不同,个数可以相同
参数相同,个数不能相同
static void Main(string[] arr) { Console.WriteLine(M(2,3)); Console.ReadKey(); } public static int M(int n1, int n2) { n1=n1+n2; return n1; } public static string M(string s1, string s2) { s1 = s1 + s2; return s1; } public static int M(int n1, int n2,int n3) { n1 = n1 + n2+n3; return n1; }