I know stack is best and easiest way, yet could it be possible to obtain the last element in a queue without having to dequeue anything?
No, you would have to convert the queue to some other collection (using ToList
or ToArray
) in order to do this. This would effectively dequeue everything in the queue.
Keep in mind that by needing the last item from a queue you have effectively proven that you are using the wrong collection to hold your data. Consider changing your collection to another type that provides all the operations you need.