Alex Rivera | Logout

Why can't static method in non-static class be an extension method?

Asked 2011-09-13T17:10:50.220
26

Possible Duplicate:
extension method requires class to be static
Why aren't C# static class extension methods supported?

In .NET:

Why can't static method in non-static class be an extension method?

Edit
Report

1 Answer

-2

At compile time whenever you use the instance syntax sugar for extension methods, this is converted into a call to the static method (which defines the extension), and passes through your instance.

Apart from the nice syntax it's no different to implementing a static method and passing your instance through as an argument. This is exactly what happens. You can't do this with static classes, as you can't pass a static class as a parameter to a method.

answered 2011-09-13T17:24:03.790

Your Answer