Queue contains special method queue.Peek(), why should I use it when I can use general queue.First() and queue.Last() ?
Queue contains special method queue.Peek() , why should I use it when I can
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Peekis a classic method of a queue, where asFirstandLastare Linq methods. Since the queue most likely implementsIEnumerableyou get the methods First and Last which have no relevance to an strict queue.EDIT
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