As in the title. Why does the Stack class need a method to return a reference of the top object? I've always been told, that methods suggest there's some computing involved and that simple objects should be returned with properties instead. Peek()
method has no parameters and on a code level it's (I think) a simple operation.
The question is: is there a speciffic reason for that? Any hidden behaviour that impacts performance?
EDIT: I don't know the class implementation, but f.e. if the method uses enumerator beneath, then iterating to the last element many times would be unwise. On the other hand if it's a single IList
, then it should not have any bigger impact on the performance.