C# 中的静态绑定是什么?
csharpprogrammingserver side programming更新于 2025/10/13 8:52:17
在编译时将函数链接到对象称为静态绑定。C# 提供了两种实现静态多态的技术:函数重载和运算符重载。
在函数重载中,同一作用域内可以对同一函数名进行多次定义。
示例
void print(int i) {
Console.WriteLine("Printing int: {0}", i );
}
void print(double f) {
Console.WriteLine("Printing float: {0}" , f);
}
重载运算符是具有特殊名称的函数。关键字"operator IS"后跟所定义运算符的符号。
示例
public static Box operant+ (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;
}

