When to use the Stack collection in C#?

后端 未结 12 2256
滥情空心
滥情空心 2021-02-14 20:44

I do understand how Stack() and Stack works, but I really can\'t see any scenarios where an array, List or IEnumer

12条回答
  •  隐瞒了意图╮
    2021-02-14 20:56

    I'd say if you were modeling something that is conceptually a stack. Say you're modeling a small, but deep drawer and you're putting books in the drawer. This will follow a "first in, last out" paradigm, which is the point of a stack in general.

    You don't have a list of books or some kind of enumeration - you have a specific ordering of them... namely, the opposite of the order in which they were added.

提交回复
热议问题