C#運算符重載用法實例分析
更新時間:2015年07月03日 12:21:04 作者:pythoner
這篇文章主要介紹了C#運算符重載用法,實例分析了C#中運算符重載的基本實現(xiàn)與使用技巧,需要的朋友可以參考下
本文實例講述了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#程序設(shè)計有所幫助。
相關(guān)文章
c#訪問this關(guān)鍵字和base關(guān)鍵字示例
this關(guān)鍵字引用類的當(dāng)前實例。靜態(tài)成員方法中不能使用this關(guān)鍵字,this關(guān)鍵字只能在實例構(gòu)造函數(shù)、實例方法或?qū)嵗L問器中使用。base關(guān)鍵字用于從派生類中訪問基類的成員。下面學(xué)習(xí)一下這二個關(guān)鍵字的使用方法2014-01-01C# Winform按鈕中圖片實現(xiàn)左圖右字的效果實例
這篇文章主要給大家介紹了關(guān)于C# Winform按鈕中圖片實現(xiàn)左圖右字效果的相關(guān)資料,文中通過圖文介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-11-11