Can you make an Extension Method Static/Shared?

Posted by Matt Thrower on Stack Overflow See other posts from Stack Overflow or by Matt Thrower
Published on 2010-05-21T09:04:11Z Indexed on 2010/05/21 9:20 UTC
Read the original article Hit count: 171

Filed under:
|

OK, I've probably misunderstood something here but, as far as I can see ...

  • An extension method has to be contained in a module, not a class
  • You can't make methods in modules Static/Shared
  • Therefore you can't use an extension method on a class without instantiating it.

In other words you can't make an extension method on String called "MyExtensionMethod" and use:

String.MyExtensionMethod("String")

But instead ..

Dim test As String
test.MyExtensionMethod("string")

Is this correct? Or is there a way I can get extension methods to work as static methods?

© Stack Overflow or respective owner

Related posts about .NET

Related posts about extension-methods