C#方法的重载

//指的是在同一个类中,定义多个方法,名字相同,但是参数不同。
//好处就是根据参数类型和个数不同选择方法
//如果参数个数相同,参数类型不能相同。如果参数类型相同,参数个数不能相同
//方法的重载和返回值没关系

static void Main(string[] args)
{

   Program.A(1, 2, 3);
   Console.WriteLine(Program.result2);

}

public static int result1, result2;
public static void A(int i1, int i2)
{

   result1 = i1 + i2;        

}

public static double A(double d1, double d2)
{

   return d1 + d2;

}

public static void A(int i1, int i2, int i3)
{

   result2 = i1 + i2 + i3;

}

public static string A(string s1, string s2)
{

   return s1 + s2;

}

posted @   菜鸟的奋斗军  阅读(12)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
点击右上角即可分享
微信分享提示