1. 程式人生 > >35.C#--方法的重載

35.C#--方法的重載

pre res turn 方法 void 根據 參數 stat ret

//方法重載,簡單說就是函數或者方法有相同的名稱,但是參數列表不相同; //這樣的同名不同參數的函數或者方法之間,我們稱之為重載函數或者方法; //main函數中調用的時候,雖然方法名字相同,但根據參數表可以自動調用對應的 函數。 public static void M(int n1, int n2) { int result = n1 + n2; } //public static int M(int a1, int a2) //{ // return a1 + a2; //} public static double M(double d1, double d2) { return d1 + d2; } public static void M(int n1, int n2, int n3) { int result = n1 + n2 + n3; } public static string M(string s1, string s2) { return s1 + s2; }

35.C#--方法的重載