Csharp/C Sharp by API/System.Collections.Generic/Queue
new Queue<T>()
using System;
using System.Collections.Generic;
class MainClass {
public static void Main() {
Queue<double> q = new Queue<double>();
q.Enqueue(9.6);
q.Enqueue(2.0);
q.Enqueue(3.0);
q.Enqueue(3.1);
double sum = 0.0;
Console.Write("Queue contents: ");
while(q.Count > 0) {
double val = q.Dequeue();
Console.Write(val + " ");
sum += val;
}
Console.WriteLine("\nTotal is " + sum);
}
}
Queue.Enqueue
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
class Program {
static void Main(string[] args) {
Queue alphabet = new Queue();
alphabet.Enqueue("A");
alphabet.Enqueue("B");
alphabet.Enqueue("C");
Console.Write("First Iteration: ");
foreach (string item in alphabet) {
Console.Write(item);
}
Console.WriteLine("\nItem pulled from collection: " +
alphabet.Dequeue().ToString());
Console.Write("Second iteration: ");
foreach (string item in alphabet) {
Console.Write(item);
}
}
}