Exemple #1
0
        static void MakeSomeBikes()
        {
            MotorCycle m1 = new MotorCycle();

            Console.WriteLine($"Intensity : {m1.DriverIntensity} && Name : {m1.DriverName}");
            MotorCycle m2 = new MotorCycle(Intensity: 7);

            Console.WriteLine($"Intensity : {m2.DriverIntensity} && Name : {m2.DriverName}");
            MotorCycle m3 = new MotorCycle(Name: "Tushar");

            Console.WriteLine($"Intensity : {m3.DriverIntensity} && Name : {m3.DriverName}");
        }
Exemple #2
0
        static void Main()
        {
            ChangeConsoleColor();
            Console.WriteLine("*******Fun with Class Type*******\n");
            DefaultConsoleColor();

            #region MainExample
            ChangeConsoleColor();
            Console.WriteLine("\nMainExample\n");
            DefaultConsoleColor();
            Car myCar = new Car();
            myCar.petName   = "Henry";
            myCar.currSpeed = 10;

            for (int i = 0; i < 10; i++)
            {
                myCar.SpeedUp(5);
                myCar.PrintState();
            }
            #endregion

            #region Understanding Constructors
            ChangeConsoleColor();
            Console.WriteLine("\nUnderstanding Constructor\n");
            DefaultConsoleColor();
            Car chuck = new Car();
            chuck.PrintState();
            #endregion

            #region Defining Custom Constructors
            ChangeConsoleColor();
            Console.WriteLine("\nDefining Custom Constructors\n");
            DefaultConsoleColor();
            Car chuck1 = new Car();
            chuck1.PrintState();

            Car Marry = new Car("Mary");
            Marry.PrintState();

            Car Daisy = new Car("Mary", 75);
            Daisy.PrintState();

            #endregion

            #region The Default Constructor Revisited
            ChangeConsoleColor();
            Console.WriteLine("\nThe Default Constructor Revisited\n");
            DefaultConsoleColor();
            MotorCycle mc = new MotorCycle();
            mc.PopAWheely();
            #endregion

            #region Reset Constrcutor and Create custom constructor
            ChangeConsoleColor();
            Console.WriteLine("\nReset Constrcutor and Create custom constructor\n");
            DefaultConsoleColor();
            MotorCycle mc1 = new MotorCycle(5);
            mc1.PopAWheely();
            #endregion

            #region Use of this keyword
            ChangeConsoleColor();
            Console.WriteLine("\nUse of this keyword\n");
            DefaultConsoleColor();
            MotorCycle c = new MotorCycle(5);
            c.SetDriverName("tiny");
            c.PopAWheely();
            Console.WriteLine($"Rider name is {c.DriverName}");
            #endregion

            #region Chaining constructor class using this && Observing construtor overflow
            ChangeConsoleColor();
            Console.WriteLine("\nChaining constructor class using this && Observing construtor overflow\n");
            DefaultConsoleColor();
            //You create your object by invoking the constructor requiring a single int.
            MotorCycle c1 = new MotorCycle(4);
            c.SetDriverName("Tushar");
            c.PopAWheely();
            Console.WriteLine($"Rider name is {c.DriverName}");
            #endregion

            #region Revisiting Optional Parameters
            ChangeConsoleColor();
            Console.WriteLine("\nRevisiting Optional Parameters\n");
            DefaultConsoleColor();
            MakeSomeBikes();
            #endregion

            Console.ReadLine();
        }