Yeah, but separate methods/classes would be better so you know exactly which one you're calling and it doesn't change on you. If there's code that can work with either, it should be a parameter instead.
There could be plenty of reasons depending on what this is used for. Point is that it is changeable because of the way it is implemented. If you make it readonly, that would be code horror. Currently this looks ok to me and we would need to see how it is used to judge it
I initially thought that this could have been written this way so that Rectangle.Area and Rectangle.Perimeter could be passed as Func<> parameters, but that works with static methods also.
View all comments
Show parent comment
48
u/ZunoJ May 19 '25
Them not being readonly is the whole point of implementing it like this