Why use queue.Peek () instead of queue.First () / Last ()

The queue contains a special queue.Peek() method, why should I use it when I can use the common queue.First() and queue.Last() ?

+4
source share
1 answer

Peek is the classic queue method, where First and Last are Linq methods. Since the queue most likely implements IEnumerable , you get First and Last methods that are not related to a strict queue.

<h / "> EDIT

This is not the end of the world to bend the law of the queue. It looks like you are using a structure appropriate to your needs. This may confuse the next programmer, although he expects the queue to act as a queue. Perhaps you are creating a class that extends Queue, called StackedQueue. Then, if someone needs to maintain their code, they do not expect queued behavior

+7
source

Source: https://habr.com/ru/post/1386343/


All Articles