Exemple #1
0
        static void Main(string[] args)
        {
            // create instance of the car class object
            Car myNewCar = new Car(); // this is a new instance of an object of the type Car
            Car fooCar   = new Car(); // another instance of the car class

            // populate it's properties
            myNewCar.Make  = "Oldsmobile";
            myNewCar.Model = "Cutlas Supreme";
            myNewCar.Year  = 1976;
            myNewCar.Color = "Silver";

            // Console out the output of the values we just assigned to the prperties of the new instance of the Car class object
            Console.WriteLine("{0} {1} {2} {3}", myNewCar.Make, myNewCar.Model, myNewCar.Year, myNewCar.Color);
            Console.WriteLine("");

            //////////////////////////////////////////////////////////////////////////////////////

            /* 2 ways to call a method to get a number for car value:
             * 1) create a helper method (as we have done below - hlpDetermineMarketValue ) that returns the value somehow
             * 2) create a class method - which we have created in the class and it is called clsDetermineMarketValue */

            // 1) call a class method to get the car value
            // call the helper method and pass it the car class instance object
            decimal decimalHelperMethodDerivedMarketValueOfCar = hlpDetermineMarketValue(myNewCar);
            // print out car value after returned from helper function
            string strHelperMethodDerivedMarketValueOfCar = string.Format("Car value returned from helper method hlpDetermineMarketValue = {0:C}", decimalHelperMethodDerivedMarketValueOfCar);

            CreateTestOutput(strHelperMethodDerivedMarketValueOfCar);

            // 2) call a class method to get the car value
            // call the class method - notice we do not pass anything we simply ask the class to return the value by calling the method on the class object
            decimal decimalClassMethodDerivedMarketValueOfCar = myNewCar.clsDetermineMarketValue();
            string  strClassMethodDerivedMarketValueOfCar     = string.Format("Car value returned from class method clsDetermineMarketValue  = {0:C}", decimalClassMethodDerivedMarketValueOfCar);

            // print out car value after returned from helper function
            CreateTestOutput(strClassMethodDerivedMarketValueOfCar);
            //////////////////////////////////////////////////////////////////////////////////////

            /* Console print out (again) the values of the properties for this new class instance (class object) using our built-in method CreateOutputAndFinish
             * string strMyNewCarInfo = myNewCar.Year + " " + myNewCar.Make + " " + myNewCar.Model + " - color: " + myNewCar.Color;
             * CreateTestOutput(strMyNewCarInfo); */
        }