Can you add extension methods to an existing static class?

Technology CommunityCategory: C#Can you add extension methods to an existing static class?
VietMX Staff asked 3 years ago

No. Extension methods require an instance variable (value) for an object. You can however, write a static wrapper class. Also extension methods is just syntactic sugar.

Consider:

public static string SomeStringExtension(this string s)
{
   //whatever..
}
// When you then call it 
myString.SomeStringExtension(); 
// the compiler just turns it into:
ExtensionClass.SomeStringExtension(myString);