-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
Hi! I used the Stack<T> collection recently to implement an algorithm, whose correctness now depends on the Stack<T> having a LIFO enumeration order. I checked the documentation to see if this enumeration order is well defined, but I can't find an explicit statement about this. I found though an old StackOverflow question, where the accepted answer (by Matthew Watson) includes this excerpt:
The Stack.GetEnumerator() strongly implies that LIFO order is used.
If you look at the example for
Stack<T>.GetEnumerator()in Microsoft's documentation and inspect the stated output, you can see that it is in LIFO order.This strongly suggests that Microsoft fully intend a Stack to be enumerated in LIFO order - but they forgot (or didn't bother to) to explicitly document this!
I would like to ask if the current LIFO behavior is just an implementation detail, or if it's a publicly documented guarantee on which algorithms can rely on.
Thanks!