日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
C# Fluent Interface概念實(shí)例淺析

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

站在用戶的角度思考問題,與客戶深入溝通,找到文成網(wǎng)站設(shè)計(jì)與文成網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗(yàn),讓設(shè)計(jì)與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個(gè)性化、用戶體驗(yàn)好的作品,建站類型包括:成都網(wǎng)站設(shè)計(jì)、網(wǎng)站制作、外貿(mào)營(yíng)銷網(wǎng)站建設(shè)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、空間域名、虛擬空間、企業(yè)郵箱。業(yè)務(wù)覆蓋文成地區(qū)。

C# Fluent Interface代碼實(shí)現(xiàn):

 
 
 
  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);  

沒有什么花俏的東西,一個(gè)可設(shè)長(zhǎng)寬的矩形接口并提供一個(gè)簡(jiǎn)單實(shí)現(xiàn)。接下來看看用另一種方式

 
 
 
  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  

這種“鏈?zhǔn)?方法調(diào)用方式是不是更接近我們?nèi)四X的思維方式,更簡(jiǎn)潔呢。沒錯(cuò), It's Fluent Interface。

個(gè)人理解的Fluent Interface 就是 在面向?qū)ο缶幊讨校褂媚撤N方式(通常但不限于使用 方法鏈方式)來實(shí)現(xiàn)更具可讀性,易用性的編程方式。而方法鏈的關(guān)鍵之處就是在方法內(nèi)部調(diào)用***要返回調(diào)用者本身。

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

沒錯(cuò),類似于 $('id').show().css('').fadeOut(); 這種就是一種Fluent Interface實(shí)現(xiàn)。

C# Fluent Interface的相關(guān)內(nèi)容就向你介紹到這里,希望對(duì)你了解和學(xué)習(xí)C# Fluent Interface有所幫助。

【編輯推薦】

  1. C# interface學(xué)習(xí)經(jīng)驗(yàn)淺談
  2. C# interface使用實(shí)例分析
  3. 淺析abstract class和interface的不同
  4. 詳解abstract class和interface的本質(zhì)
  5. 關(guān)于interface繼承來源的討論

本文題目:C# Fluent Interface概念實(shí)例淺析
文章源于:http://m.5511xx.com/article/dpejjeg.html