Bob Tway
Bob Tway

Reputation: 9613

Can you make an Extension Method Static/Shared?

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

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?

Upvotes: 8

Views: 712

Answers (1)

LukeH
LukeH

Reputation: 269528

You are correct. Extension methods can only act on instances of a type.

And no, unfortunately there's no crafty way to write extension methods that act on the types themselves, behaving like static methods.

Upvotes: 10

Related Questions