欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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#程序设计有所帮助。