Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't I create extension methods for static classes?

When I try to create an extension method for the File class, I get an error telling me that I cannot do this because the class is static. However, I don't see why this stops the creation of an extension method, what implication is there?

Thanks

like image 721
GurdeepS Avatar asked Mar 07 '10 23:03

GurdeepS


1 Answers

Extension methods are called on an instance of an object.

myObj.ExtensionMethod();

If you have a static class, you can't have an instance of it. Therefore, there's nothing to call the extension method on.

like image 133
kyoryu Avatar answered Sep 20 '22 12:09

kyoryu