在编译期间函数与对象的链接称为静态绑定。 C# 提供了两种实现静态多态性的技术:函数重载和运算符重载。
在函数重载中,同一作用域内的同一个函数名可以有多个定义。
示例void print(int i) {
Console.WriteLine("Printing int: {0}", i );
}
void print(double f) {
Console.WriteLine("Printing float: {0}" , f);
}
重载运算符是具有特殊名称的函数。关键字运算符 IS 后跟用于定义 D 的运算符的符号。
示例
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; }
以上就是C# 中的静态绑定是什么?的详细内容,更多请关注编程之家其它相关文章!