Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Actually most of the extension methods in the BCL apply not to classes, but to interfaces, which is a key power of extension methods.</p> <p>For example, almost all of LINQ to objects is implemented as extensions to the <code>IEnumerable&lt;T&gt;</code> interface, and not to the classes <code>List&lt;T&gt;, HashSet&lt;T&gt;</code>, etc.</p> <p>Because interfaces do not have functionality (just a contract), adding an extension method to a interface gives you a way to an interface itself. This is especially handy when the implementation need only know of the interface for it's use and not implementation specifics (per se).</p> <p>Microsoft <em>does</em> add new methods in their BCL classes all the time (though of course they avoid breaking changes wherever possible). But I believe the majority of their extension method use in the BCL is on interfaces and not for adding functionality that could easily be added with a new method directly to the class/struct.</p> <p>So, in short, when Microsoft chooses to add functionality to a single <code>class</code> (or family with a common base class), they'd probably just add the method directly (all things being equal), but if they wanted to apply a new method to all implementations of a given interface, they'd probably use an extension method on that interface.</p> <p>Also keep in mind this! Because Microsoft gave us extension methods, it applies to classes they didn't create as well! For example, any class that you create that implements <code>IEnumerable&lt;T&gt;</code> gets the functionality of LINQ as well as a bonus, even though you inherit no common base classes, etc. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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