C#运算符重载用法实例分析
程序员文章站
2023-11-17 14:44:22
本文实例讲述了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#程序设计有所帮助。
上一篇: java 实现文件复制和格式更改的实例
下一篇: mysql学习笔记之基础知识