1/19
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai | Chat |
|---|
No analytics yet
Send a link to your students to track their progress
Queue
A generic collection in System.Collections.Generic that stores elements for first-in, first-out (FIFO) processing. Domain: C# → .NET → System.Collections.Generic → Queue
FIFO
First In, First Out; the element that has been waiting in the Queue the longest is the next element removed.
Front of a Queue
The end of a Queue from which the next element is inspected or removed.
Back of a Queue
The end of a Queue where newly enqueued elements are added.
new Queue
Creates an empty Queue
new Queue
Creates a Queue
queue.Count
Gets the number of elements currently contained in the Queue.
queue.Enqueue(item)
Adds an element to the back of the Queue.
queue.Dequeue()
Removes and returns the element at the front of the Queue; throws InvalidOperationException if the Queue is empty.
queue.Peek()
Returns the element at the front of the Queue without removing it; throws InvalidOperationException if the Queue is empty.
queue.TryDequeue(out result)
Attempts to remove and return the element at the front of the Queue, returning false if the Queue is empty.
queue.TryPeek(out result)
Attempts to return the element at the front of the Queue without removing it, returning false if the Queue is empty.
queue.Contains(item)
Determines whether the specified element occurs in the Queue.
queue.Clear()
Removes all elements from the Queue.
queue.ToArray()
Copies the Queue elements into a new array in FIFO order.
queue.TrimExcess()
Reduces excess internal storage capacity when appropriate relative to the number of elements currently stored.
Enqueue vs Dequeue
Enqueue adds an element to the back of a Queue, whereas Dequeue removes and returns an element from the front.
Dequeue vs Peek
Dequeue returns and removes the front element, whereas Peek returns the front element without removing it.
TryDequeue vs Dequeue
TryDequeue safely reports failure when the Queue is empty, whereas Dequeue throws an InvalidOperationException.
Queue
Queue