Why is Stack.Peek() a method?

c#, peek, stack

Solution

Peek is a verb, so in my book `Peek()` should be a method. However with a different name it could also be a property.

Remember that any property has associated get and/or set methods, so you'd end up with a method either way.

Problem

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.

Original source