Example #1
0
              statis void Main(string[] args)
          {
              DrinksMachine myMachine = new DrinksMachine();
              myMachine._location = "kitchen";
              myMachine._model = "DM1000";

          }
        //Classes and Delegates are always reference types
        //Structs are value types
        static void Main(string[] args)
        {
            Module03BasicTypesAndConstructs.Coffee firstBean = new Module03BasicTypesAndConstructs.Coffee(5, "Good Beans", "My Place");
            firstBean.OutOfBeans += new Inventory().HandleOutOfBeans;
            DrinksMachine dm = new DrinksMachine
            {
                Age   = 2,
                Model = "BeanSmasher 3000",
                Make  = "Fourth Coffee"
            };

            for (int x = 0; x < 4; x++)
            {
                dm.MakeCappuccino(ref firstBean);
            }
            DrinksMachine dm2 = new DrinksMachine(2);
            DrinksMachine dm3 = new DrinksMachine("Fourth Coffee", "BeanDestroyer 3000");
            DrinksMachine dm4 = new DrinksMachine(3, "Fourth Coffee", "BeanToaster Turbo");

            //Boxing is converting a value type to a reference type by wrapping it in an object
            int    i   = 100;
            object obj = i;
            // Unboxing is converting a reference type to a value type and you must explicitly cast the variable back to its original type
            int j;

            j = (int)obj;

            double weightInKilos  = 80;
            double weightInPounds = Conversions.KilosToPounds(weightInKilos);
            //Using IComparer implentation to sort coffee by rating rather than Variety (default set by coffee class IComparable implentation)
            //Coffee Class (rather than coffee struct above)
            Coffee coffeenew1 = new Coffee();

            coffeenew1.AverageRating = 4.5;
            Coffee coffeenew2 = new Coffee();

            coffeenew2.AverageRating = 8.1;
            Coffee coffeenew3 = new Coffee();

            coffeenew3.AverageRating = 7.1;
            //Add the instances to arraylist
            ArrayList coffeList = new ArrayList();

            coffeList.Add(coffeenew1);
            coffeList.Add(coffeenew2);
            coffeList.Add(coffeenew3);
            //Sort arraylist by average rating(passed custom Icomparer implentation)
            coffeList.Sort(new CoffeeRatingComparer());
            foreach (Coffee drink in coffeList)
            {
                Console.WriteLine(drink.AverageRating);
            }
            Console.ReadLine();
        }
Example #3
0
        static void Main(string[] args)
        {
            DrinksMachine myMachine = new DrinksMachine("Kitchen", "Brand", "DM1000");

            // myMachine.Location = "Kitchen";
            // myMachine.Model = "DM1000";

            Console.WriteLine(myMachine.Location);
            Console.WriteLine(myMachine.Make);
            Console.WriteLine(myMachine.Model);
            myMachine.MakeCappuccino();
        }