成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

C# Fluent Interface概念實例淺析

開發 后端
C# Fluent Interface是什么呢?對于C# Fluent Interface我們是如何實現的呢?那么本文就向你詳細介紹相關內容。

C# Fluent Interface是如何實現的呢?首先我們來看看Fluent Interface,直譯過來是 “流暢(流利)的接口”,照字面有點難以理解,那么Fluent Interface是如何實現的呢?下面讓我們從代碼上向你介紹:

C# Fluent Interface代碼實現:

  1. public interface IRect  
  2. {  
  3. void SetWidth(int width);  
  4. void SetHeight(int height);  
  5. }  
  6. public Rect : IRect  
  7. {  
  8. private int _width;  
  9. private int _height;  
  10. public void SetWidth(int width) { this._width = width; }  
  11. public void SetHeight(int height){ this_height = height; }  
  12. }  
  13. public static void Main(string [] args)  
  14. {  
  15. IRect rect = new Rect();  
  16. rect.SetHeight(10);  
  17. rect.SetWidth(50);  

沒有什么花俏的東西,一個可設長寬的矩形接口并提供一個簡單實現。接下來看看用另一種方式

  1. public interface IRectFluent  
  2. {  
  3. IRectFluent SetWidth(int width);  
  4. IRectFluent SetHeight(int height);  
  5. }  
  6. public RectFluent : IRectFluent  
  7. {  
  8. private int _width;  
  9. private int _height;  
  10. public IRectFluent SetWidth(int width) { this._width = width; return this; }  
  11. public IRectFluent SetHeight(int height){ this_height = height; return this; }  
  12. }  
  13. public static void Main(string [] args)  
  14. {  
  15. IRectFluent rect = new RectFluent();  
  16. rect.SetHeight(10).SetWidth(50);  // checkpoint  

這種“鏈式"方法調用方式是不是更接近我們人腦的思維方式,更簡潔呢。沒錯, It's Fluent Interface。

個人理解的Fluent Interface 就是 在面向對象編程中,使用某種方式(通常但不限于使用 方法鏈方式)來實現更具可讀性,易用性的編程方式。而方法鏈的關鍵之處就是在方法內部調用***要返回調用者本身。

所謂Fluent借助于wikipedia的說法就是‘This style is beneficial due to its ability to provide a more fluid feel to the code."
說到這里,經常使用jquery的朋友肯定感覺很熟悉上面的使用方式。

沒錯,類似于 $('id').show().css('').fadeOut(); 這種就是一種Fluent Interface實現。

C# Fluent Interface的相關內容就向你介紹到這里,希望對你了解和學習C# Fluent Interface有所幫助。

【編輯推薦】

  1. C# interface學習經驗淺談
  2. C# interface使用實例分析
  3. 淺析abstract class和interface的不同
  4. 詳解abstract class和interface的本質
  5. 關于interface繼承來源的討論
責任編輯:仲衡 來源: 博客園
相關推薦

2009-08-27 13:30:11

C# interfac

2009-08-27 14:12:02

C# interfac

2009-08-27 15:17:18

C# interfacinterface使用

2009-09-14 13:44:14

Lambda ExprC# Lambda

2009-08-17 17:49:20

C# 枚舉

2009-09-09 13:57:28

C# XML解析

2009-09-02 10:58:02

C#動態數組

2009-08-27 17:59:56

C#接口定義

2009-08-18 13:49:21

C# 操作Excel

2009-09-09 16:46:59

C# XmlSeria

2009-08-24 14:26:42

C# 泛型類

2009-08-18 16:04:12

C# 操作Excel

2009-08-19 09:42:52

C#操作Word書簽

2009-08-28 17:34:14

讀取word文檔

2009-08-31 18:38:59

C#寫文件

2009-08-12 15:26:38

C#讀取XML文檔

2009-08-19 11:13:49

C#操作Word

2009-09-03 14:55:34

C#計算時間間隔

2009-09-01 13:13:28

C#打開Word文檔

2009-08-19 11:34:06

C#操作Word
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 毛片黄片免费看 | 秋霞在线一区 | av国产精品 | 成人福利在线视频 | 国产成人99久久亚洲综合精品 | 一区二区三区在线免费观看 | 国产黄色麻豆视频 | 国产乱肥老妇国产一区二 | 欧美区在线 | 国产一级免费视频 | 久久久www成人免费无遮挡大片 | 日韩精品欧美精品 | 国产亚洲二区 | av一级一片 | 一区二区三区小视频 | 欧美一级黄 | 欧美三区在线观看 | 97精品国产手机 | 天天干在线播放 | 伊人看片 | 91成人午夜性a一级毛片 | 亚洲高清在线观看 | 女人牲交视频一级毛片 | 天天天操天天天干 | 久久久久久成人 | 国产精品久久久久久久久久软件 | 999久久久 | 久久99精品视频 | 欧美精品一区二区三区在线播放 | a级黄色毛片免费播放视频 国产精品视频在线观看 | 国产 欧美 日韩 一区 | 九色国产 | 91原创视频在线观看 | 国产毛片av | 自拍偷拍第一页 | 欧美成人a∨高清免费观看 老司机午夜性大片 | 亚洲欧美在线视频 | 久久免费看 | 国产欧美日韩综合精品一区二区 | www.色综合 | 久久爱黑人激情av摘花 |