重载在C#中有两种类型。
在同一个作用域中,可以为同一个函数名具有多个定义。函数的定义必须在参数列表中的参数类型和/或数量上彼此不同。
让我们看一个例子-
public static int mulDisplay(int one, int two) { } public static int mulDisplay(int one, int two, int three) { } public static int mulDisplay(int one, int two, int three, int four) { }
重载运算符是具有特殊名称的函数。关键字运算符后跟要定义的运算符的符号。
public static Box operator+ (Box b, Box c) { Box box = new Box(); box.length = b.length + c.length; box.breadth = b.breadth + c.breadth; box.height = b.height + c.height; return box; }