Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Extension methods shine wherever functional programming is used.</p> <p>Consider almost any Module-level functions you already have in your app and what they become when you tag them as extension methods. They become an opportunity for "active voice" over "passive voice". Active voice means the code reads as though an instance provides its own method for performing a particular task, rather than having the function perform an action passively on it.</p> <pre><code>ExtendUnlimitedCredit(AddVIP(tblCustomer, "Bill Gates")) </code></pre> <p>vs.</p> <pre><code>tblCustomer.AddVIP("Bill Gates").ExtendUnlimitedCredit() </code></pre> <p>Extension methods make this transformation simple. Eliminating nested function calls with "active voice" code is often an improvement. Plus, since our shop locks down its core classes, we were only able to utilize nested function calls prior to extension methods.</p> <p>The other great things about extension methods:</p> <ol> <li><p>They make your functions (because of Intellisense) more discoverable. And if you provided inline markup describing the purpose and use of your function, Intellisense will even provide a helpful tooltip describing the method and its use to the developer who discovers it (simply by pressing the dot). Functions not tagged as extension methods are not so readily discovered, may go unused and, as a result, someone else may invent their own flavor of said function.</p></li> <li><p>Whereas you cannot actually implement a method for an interface, a extension method offers an alternate means that gives the appearance that you’ve done so.</p></li> </ol>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload