xxxxxxxxxx
Queue is a special type of collection that stores the elements in FIFO style (First In First Out)
xxxxxxxxxx
using System;
using System.Collections.Generic;
class Program
{
static void Main()
{
// Create a queue to store first names and last names
Queue<string> nameQueue = new Queue<string>();
// Add items to the queue
nameQueue.Enqueue("John"); // Adding a first name
nameQueue.Enqueue("Doe"); // Adding a last name
// You can continue to enqueue more names as needed
// Iterate to retrieve values from the queue
while (nameQueue.Count > 0)
{
// Dequeue removes and returns the item at the front of the queue
string name = nameQueue.Dequeue();
Console.WriteLine(name);
}
}
}
xxxxxxxxxx
public void Clear ();
//Removes all objects from the Queue<T>.
public bool Contains (T item);
//Determines whether an element is in the Queue<T>.
public void CopyTo (T[] array, int arrayIndex);
//Copies the Queue<T> elements to an existing one-dimensional Array,
//starting at the specified array index.
public T Dequeue ();
//Removes and returns the object at the beginning of the Queue<T>.
public void Enqueue (T item);
//Adds an object to the end of the Queue<T>.
public T Peek ();
//Returns the object at the beginning of the Queue<T> without removing it.
public T[] ToArray ();
//Copies the Queue<T> elements to a new array.
public bool TryPeek (out T result);
//Returns a value that indicates whether
//there is an object at the beginning of
//the Queue<T>, and if one is present,
//copies it to the result parameter.
//The object is not removed from the Queue<T>.