在编译期间函数与对象的链接称为静态绑定。 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# 中的静态绑定是什么?的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号