0
点赞
收藏
分享

微信扫一扫

C#(三):方法的定义、方法的重载


方法定义

​[访问权限修饰符] [其他的修饰符] 返回值类型 方法名 ([行参列表]) { /* 方法体 */ }​

public static string FunA(string str)
{

Console.WriteLine(str);

return str;

}

重载

在一个类中,如果由多个方法满足以下几个条件,那么这几个方法是重载关系

  1. 方法名相同
  2. 参数不同 (数量不同,类型不同)
  3. 跟返回值无关系

class MainClass
{
public static void Main(string[] args)
{

Add(1);

Add(1, 1f);

}

static void Add(int a, float b)
{
Console.WriteLine(a + b);
}

static int Add(int a)
{
return a;
}

}


举报

相关推荐

0 条评论