6 ms·
> but only if they are methods on the class C# got around this by introducing extension methods. You put static methods inside any static class whose namespace
by ziml77 5y ago
> but only if they are methods on the class
C# got around this by introducing extension methods. You put static methods inside any static class whose namespace you've imported and label the first parameter with `this` before the type name. Then you're able to call that static method as if it was an instance method on anything that is or implements the type of the first parameter. Basically it's an explicit version of D's unified function call syntax.
I think the pipeline operator is nicer, but extension methods aren't a bad solution.
- runevault 5y agoSure, you can fake it to get to the same place. And I've abused extension methods a lot, including on interfaces before c# made default implementations on interfaces a more acceptable thing with c#... 9 I think?