using System.Collections.Generic;
public static void Main(string[] args)
Queue<Customer> customerList = new Queue<Customer>();
customerList.Enqueue(new Customer("Minesh", "G."));
customerList.Enqueue(new Customer("Pramila", "S."));
customerList.Enqueue(new Customer("Krish", "G."));
customerList.Enqueue(new Customer("Manju", "G."));
customerList.Enqueue(new Customer("Mandita", "G."));
Table table = new Table();
while (customerList.Count > 0)
Customer anotherCustomer = customerList.Dequeue();
anotherCustomer.CustomerEvent += CustomerMeal;
table.TableEvent += anotherCustomer.OpenTable;
while (anotherCustomer.lunch != Customer.Lunch.done)
anotherCustomer.NextLunch();
table.TableEvent -= anotherCustomer.OpenTable;
Console.WriteLine("Everyone is full!");
public static void CustomerMeal(object sender, CustomerInfoEventArgs e)
Console.WriteLine("{0} {1} is having {2}.", e.customer.fName, e.customer.lName, e.customer.lunch);
public enum Lunch { none, appetizer, main, desert, done }
public EventHandler<CustomerInfoEventArgs> CustomerEvent;
public string fName { get; set; }
public string lName { get; set; }
public Lunch lunch { get; set; }
public Customer(string _fName, string _lName)
public void OpenTable(object sender, TableInfoEventArgs e)
Console.WriteLine("{0} {1} got a table.", this.fName, this.lName);
EventHandler<CustomerInfoEventArgs> customerMealInfo = CustomerEvent;
this.lunch = Lunch.appetizer;
this.lunch = Lunch.desert;
if (customerMealInfo != null)
customerMealInfo(this, new CustomerInfoEventArgs(this));
public class CustomerInfoEventArgs : EventArgs
public Customer customer { get; private set; }
public CustomerInfoEventArgs(Customer customer)
this.customer = customer;
public EventHandler<TableInfoEventArgs> TableEvent;
Console.WriteLine("Table open!");
EventHandler<TableInfoEventArgs> tableOpenInfo = TableEvent;
if (tableOpenInfo != null)
tableOpenInfo(this, new TableInfoEventArgs(this));
public class TableInfoEventArgs : EventArgs
public Table table { get; private set; }
public TableInfoEventArgs(Table table)