C#运算符重载用法实例分析
程序员文章站
2023-12-05 22:51:34
本文实例讲述了c#运算符重载用法。分享给大家供大家参考。具体分析如下:
public class plane {
public virtual doubl...
本文实例讲述了c#运算符重载用法。分享给大家供大家参考。具体分析如下:
public class plane { public virtual double topspeed() { return 300.0d;} public static bool operator>(plane one, plane two) { return one.topspeed() > two.topspeed(); } public static bool operator<(plane one, plane two) { return one.topspeed() < two.topspeed(); } } class jet : plane { public override double topspeed() { return 900.0d; } public override string tostring() { return "i'm a jet"; } } class airport { [stathread] static void main(string[] args) { plane plane = new jet(); console.writeline("plane's top speed: {0}",plane.topspeed()); jet jet = new jet(); console.writeline("jet's top speed: {0}",jet.topspeed()); console.writeline("plane > jet = {0}", plane > jet); console.readline(); } }
希望本文所述对大家的c#程序设计有所帮助。
上一篇: 有效提升网站运营效率的方法有哪些?
下一篇: 微信提现API实现(企业付款到个人)