In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "how to achieve C # Fluent Interface". In daily operation, I believe many people have doubts about how to realize C # Fluent Interface. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to achieve C # Fluent Interface". Next, please follow the editor to study!
C # Fluent Interface code implementation:
Public interface IRect {void SetWidth (int width); void SetHeight (int height);} public Rect: IRect {private int _ width; private int _ height; public void SetWidth (int width) {this._width = width;} public void SetHeight (int height) {this_height = height;}} public static void Main (string [] args) {IRect rect = new Rect (); rect.SetHeight (10); rect.SetWidth (50);}
There is nothing fancy, a rectangular interface that can be set long and wide and provides a simple implementation. Let's take a look at it in another way.
Public interface IRectFluent {IRectFluent SetWidth (int width); IRectFluent SetHeight (int height);} public RectFluent: IRectFluent {private int _ width; private int _ height; public IRectFluent SetWidth (int width) {this._width = width; return this;} public IRectFluent SetHeight (int height) {this_height = height; return this;}} public static void Main (string [] args) {IRectFluent rect = new RectFluent (); rect.SetHeight (10) .SetWidth (50); / / checkpoint}
Is this "chained" method call more similar to our brain's way of thinking, more concise? That's right, It's Fluent Interface.
Personal understanding of Fluent Interface is in object-oriented programming, the use of a certain way (usually but not limited to the use of method chain mode) to achieve more readable, easy-to-use programming. The key to the method chain is to call * * inside the method to return to the caller itself.
The so-called Fluent with the help of wikipedia is' This style is beneficial due to its ability to provide a more fluid feel to the code. "
Speaking of which, friends who use jquery a lot must feel familiar with how to use it.
Yes, it is similar to $('id'). Show (). Css ('). FadeOut (); this is a Fluent Interface implementation.
At this point, the study of "how to implement C # Fluent Interface" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.