Queue contains special method queue.Peek()
, why should I use it when I can use general queue.First()
and queue.Last()
?
Peek
is a classic method of a queue, where as First
and Last
are Linq methods. Since the queue most likely implements IEnumerable
you get the methods First and Last which have no relevance to an strict queue.
It's not the end of the world to bend the law of a queue. Sounds like you are using the structure to fit your needs. It might be confusing to the next programmer though who expects a queue to act like a queue. Maybe you create a class that extends Queue, called a StackedQueue. Then if someone needs to maintain your code they won't expect a queue's behavior
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With