C#基礎之方法的重載
- 2020 年 5 月 28 日
- 筆記
在C#語言中,方法的重載作用非常大,但是使用重載需要注意方法的簽名,必須有一種要不一樣,具體指的是:
1、方法的返回值類型
2、方法的形參類型
3、形參類型的順序
4、形參的個數
4、泛型的類型<string>
5、形參的修飾符如:out
1 class Program 2 { 3 static void Main(string[] args) 4 { 5 6 Console.WriteLine(Student.Age(2,4.0)); 7 } 8 static class Student 9 { 10 public static double Age(double a, double b) 11 { 12 return 3.14 * a * b; 13 } 14 public static double Age(int a) 15 { 16 return 3.14 * a; 17 } 18 public static double Age(int a, double b) 19 { 20 return a * b; 21 } 22 public static int Age(int a,int b,int h) 23 { 24 return a * b * h; 25 } 26 } 27 }