Why does the extract method command in visual studio create static methods?

Why does Visual Studio by default create a private static method when refactoring code and selecting extract method?

It does this only if your method doesn’t access any member variables/methods/properties. This is good because it basically operates on the principle of least assumptions: since you don’t access instance-specific data, might as well make the method static.

Is there some performance benefit by calling a private static method within a non-static class compared to a non-static method within a non-static class?

Theoretically, there might be but I doubt it. However, making the method static makes it clear that it will not access or modify instance data, which I find a useful hint.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)