C#运算符重载用法实例分析
本文实例讲述了C#运算符重载用法。分享给大家供大家参考。具体分析如下:
publicclassPlane{ publicvirtualdoubleTopSpeed(){return300.0D;} publicstaticbooloperator>(Planeone,Planetwo){ returnone.TopSpeed()>two.TopSpeed(); } publicstaticbooloperator<(Planeone,Planetwo){ returnone.TopSpeed()<two.TopSpeed(); } } classJet:Plane{ publicoverridedoubleTopSpeed(){return900.0D;} publicoverridestringToString(){return"I'maJet";} } classAirport{ [STAThread] staticvoidMain(string[]args){ Planeplane=newJet(); Console.WriteLine("plane'stopspeed:{0}",plane.TopSpeed()); Jetjet=newJet(); Console.WriteLine("jet'stopspeed:{0}",jet.TopSpeed()); Console.WriteLine("Plane>Jet={0}",plane>jet); Console.ReadLine(); } }
希望本文所述对大家的C#程序设计有所帮助。