Put user-defined objects to Queue collection : Queue « Collections Data Structure « C# / C Sharp






Put user-defined objects to Queue collection

    

using System;
using System.Collections;

public class Starter {
    public static void Main() {
        Queue waiting = new Queue();
        waiting.Enqueue(new Customer("B"));
        waiting.Enqueue(new Customer("T"));
        waiting.Enqueue(new Customer("K"));
        waiting.Enqueue(new Customer("S"));

        while (waiting.Count != 0) {
            Customer cust =
                (Customer)waiting.Dequeue();
            Console.WriteLine(cust.Name);
        }
    }

    public class Customer {
        public Customer(string cName) {
            propName = cName;
        }

        private string propName;
        public string Name {
            get {
                return propName;
            }
        }
    }
}

   
    
    
  








Related examples in the same category

1.Put elements into a queue
2.Implements the queue data type using an arrayImplements the queue data type using an array
3.A queue class for charactersA queue class for characters
4.illustrates the use of a Queueillustrates the use of a Queue
5.Queue testQueue test
6.Add exception handling to the queue classesAdd exception handling to the queue classes
7.Demonstrate the Queue classDemonstrate the Queue class
8.Priority Queue
9.Queue(T) Class represents a first-in, first-out collection of objects.
10.Priority Queue (2)
11.Dequeue
12.Implements a non-locking queue
13.Task queue
14.Cyclic Queue
15.Syncronized Queue