C# 中的静态绑定是什么?
在编译时将函数与对象链接的过程称为静态绑定。C# 提供了两种实现静态多态性的技术:函数重载和运算符重载。
在函数重载中,可以在同一个作用域中针对同一函数名称拥有多个定义。
示例
void print(int i) { Console.WriteLine("Printing int: {0}", i ); } void print(double f) { Console.WriteLine("Printing float: {0}" , f); }
重载的运算符是具有特殊名称的函数。关键词 operator 后面跟着要定义的运算符符号。
示例
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; }
广告