This is a purely hypothetical question.
Say I create a class method that contains no references to instance variables or other resources. For example (C#):
protected string FormatColumn(string value, int width)
{
return value.Trim().PadLeft(width);
}
As far as I can see, there is absolutely no reason why this method could not be declared static:
- It only uses method-scope variables.
- It doesn't
override
a base class method. - It's not
virtual
orabstract
.
My questions are:
Is there any benefit to calling a static method over an instance method?
If so, why doesn't the compiler implicitly convert this to a static method?
I'm certain I've missed some key point here. Any ideas?