方法定义
[访问权限修饰符] [其他的修饰符] 返回值类型 方法名 ([行参列表]) { /* 方法体 */ }
public static string FunA(string str)
{
Console.WriteLine(str);
return str;
}
重载
在一个类中,如果由多个方法满足以下几个条件,那么这几个方法是重载关系
- 方法名相同
- 参数不同 (数量不同,类型不同)
- 跟返回值无关系
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;
}
}