Extending Interface Types via Extension Methods
At this point, you have seen how to extend classes (and, indirectly, structures that follow the same
syntax) with new functionality via extension methods. To wrap up our investigation of C# 2008
extension methods, allow me to point out that it is possible to extend an interface type with new
methods; however, the semantics of such an action are sure to be a bit different from what you
might expect.
Create a new Console Application named InterfaceExtensions and define a simple interface
type (IBasicMath) that contains a single method named Add(). Next, implement this interface on a
class type (MyCalc) in a fitting manner. For example:
Do'stlaringiz bilan baham: