| ||Data Access, Properties, and Methods - slide 28 : 29|
In C# 3.0 an extension method defines an instance method in an existing class
without altering the definition of the class.
Motivation: A Client of Point without use of DistanceTo.
A Client of class Point which uses an extension method DistanceTo.
The static class PointExtensions.
- An extension method
- extends the type of the first parameter
- is defined as a static method with a this modifier on the first parameter
- must be defined in a static class
- cannot access private instance variables in the extended class
- is called by - behind the scene - translating to a call of the static method
Extending struct Double