usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;namespaceQueue Test {classProgram {Static voidMain (string[] args) {Queue<string> strlist =Newqueue<string>(); ///adding elements to a queueStrlist.enqueue ("element 1"); Strlist.enqueue ("element 2"); Strlist.enqueue ("element 3"); ///traversing elements foreach(varIteminchstrlist) {Console.WriteLine (item); } ///Captain LengthConsole.Write ("Queue Length---"); Console.WriteLine (Strlist.count); ////Remove the first added elements, and delete, fully reflect the first -in-a-out characteristics of the queue///If there are no elements in the queue, an exception is thrown //string mes = Strlist.dequeue (); //Console.WriteLine (MES); ///Remove The elements that were first queued, but do not delete stringMes =Strlist.peek (); Console.Write ("remove elements from the team header without removing them----"); Console.WriteLine (MES); ///traverse Queue, still three elementsConsole.WriteLine ("the remaining elements of the queue are---"); foreach(varIteminchstrlist) {Console.WriteLine (item); } ///directly obtains an element in the queue,///throws an exception if the index is out of boundsConsole.Write ("gets the 2nd element in a queue----"); strings = Strlist.elementat (2); Console.WriteLine (s); ///directly obtains an element in the queue,///if the index is out of bounds, NULL is returned, but no exception is thrownConsole.Write ("gets the 5th element in a queue-----"); Console.WriteLine (Strlist.elementatordefault (5)); Console.Write ("gets the 1th element in a queue-----"); Console.WriteLine (Strlist.elementatordefault (1)); ///Remove The elements that were first queued, but do not delete stringPop =Strlist.dequeue (); Console.Write ("remove elements from the team head----"); Console.WriteLine (MES); ///traverse the queue for 2 elementsConsole.WriteLine ("the remaining elements of the queue are---"); foreach(varIteminchstrlist) {Console.WriteLine (item); } console.readkey (); } }}
C # Queued Queue