Reputation: 8144
Is there a way to create an extension method for an type ? I only seem to be able to create them for instances.
public static class MyExtensions
{
public static string Test(this string s)
{
return "test";
}
}
public class Test
{
static void TestIt()
{
string.Test(); // won't compile
string s = null;
s.Test();
}
}
Upvotes: 2
Views: 170
Reputation: 19011
Right answer: No. Extension methods is methods for instances of some class.
You can have more information from MSDN
Upvotes: 0
Reputation: 292345
No, it's not possible. Extension methods can only be created for instances
Upvotes: 5
Reputation:
No. Extension methods are only for instances. In other words, it is not possible to have static extension methods.
Upvotes: 2