public void setNextDispenser(Cashdispenser dispenser)
 {
     if (this.next == null)
     {
         this.next = dispenser;
     }
     else
     {
         this.next.setNextDispenser(dispenser);
     }
 }
        public static void Main(string[] args)
        {
            Cashdispenser cd = new Cashdispenser(2000);

            cd.setNextDispenser(new Cashdispenser(500));
            cd.setNextDispenser(new Cashdispenser(200));
            cd.setNextDispenser(new Cashdispenser(100));
            cd.setNextDispenser(new Cashdispenser(50));
            cd.setNextDispenser(new Cashdispenser(20));
            cd.setNextDispenser(new Cashdispenser(10));
            cd.setNextDispenser(new Cashdispenser(5));
            cd.setNextDispenser(new Cashdispenser(2));
            cd.setNextDispenser(new Cashdispenser(1));

            cd.Dispense(523418);
            Console.ReadKey();
        }
 public Cashdispenser(int val)
 {
     next        = null;
     denominator = val;
 }