zxbls

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     }

 

分类:

技术点:

相关文章:

  • 2021-11-28
  • 2021-06-29
  • 2021-10-31
  • 2022-01-22
  • 2020-05-03
  • 2021-11-09
  • 2021-09-07
  • 2022-01-02
猜你喜欢
  • 2021-12-31
  • 2021-08-03
  • 2021-08-01
  • 2021-08-08
  • 2020-07-26
  • 2021-09-07
  • 2020-04-23
相关资源
相似解决方案