Why do Queue(T) and Stack(T) not implement ICollection(T)?

后端 未结 3 1042
眼角桃花
眼角桃花 2021-02-01 07:54

Before I even ask, let me get the obvious answer out of the way: The ICollection interface includes a Remove method to remove an arbitrary

3条回答
  •  粉色の甜心
    2021-02-01 08:28

    Ultimately perhaps they are just not ideal fits; if you want a list or collection - use a List or Collection ;p

    Re Add - there is an implicit assumption that Add adds to the end of the collection, which is not true of a stack (although it is for a queue). In some ways, it actually confuses me that the enumerator for stack/queue does not dequeue/pop, since I largely expect items in a queue/stack to be fetched once each (and once only).

    Maybe also (again, using my enumerator as just an example) people simply couldn't agree on exactly how it should behave in some of those scenarios, and lacking complete agreement, simply not implementing them was a better choice.

提交回复
热议问题