MyExtMeths
. As explained, an extension method must be declared within a static class.
Furthermore, this class must be in scope in order for the extension methods that it contains
to be used. (This is why you needed to include the
System.Linq
namespace to use the LINQ-
related extension methods.) Next, notice the calls to the extension methods. They are
invoked on an object, in just the same way that an instance method is called. The main
difference is that the invoking object is passed to the first parameter of the extension
method. Therefore, when the expression
val.AbsDivideBy(-2)
executes,
Do'stlaringiz bilan baham: |