C#基础之方法的重载

在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     }

猜你喜欢

转载自www.cnblogs.com/zxbls/p/12983917.html