Methods in C# are non-virtual by default. This answer to another question explains the advantage of doing it this way:
Classes should be designed for inheritance to be able to take advantage of it. Having methods virtual by default means that every function in the class can be plugged out and replaced by another, which is not really a good thing.
Even Anders Hejlsberg seems to give the same reason:
When we publish a virtual method in an API, we not only promise that when you call this method, x and y will happen. We also promise that when you override this method, we will call it in this particular sequence with regard to these other ones and the state will be in this and that invariant. [...] You don't want users overriding and hooking at any arbitrary point in an API, because you cannot necessarily make those promises.
I agree with this reasoning: Usually when I create a non-private method, I just want to create code that can be called from somewhere outside the class. Usually, no thought is given to how somebody else might override this method and which effect that would have. For the special cases, I can use virtual
to signal that did create the code in a way where overriding makes sense.
However, classes still unsealed by default. The default assumes that I spend the extra effort of making sure that inheriting a class makes sense.
Is there anything that makes a class different from a method in this regard?
EDIT
I don't really know what to change about the on hold - opinion based thing. I never asked for opinions. Maybe I have to say it explicitly?
I don't want opinions.
A correct answer would either provide an example of a class being different from a method, or state that there is no difference in this context.