Example #1
0
        static void Main(string[] args)
        {
            Car myCar = new Car();

            Car.MyMethod();


            myCar.Make  = "Oldmobile";
            myCar.Model = "Cutlas Supreme";
            myCar.Year  = 1986;
            myCar.Color = "Silver";


            Car myThirdCar = new Car("Ford", "Focus", 1990, "Blue");

            Console.WriteLine("{0} {1} {2} {3}", myThirdCar.Make, myThirdCar.Model, myThirdCar.Year, myThirdCar.Color);

            Car myOtherCar;

            myOtherCar = myCar;

            Console.WriteLine("{0} {1} {2} {3}", myOtherCar.Make, myOtherCar.Model, myOtherCar.Year, myOtherCar.Color);

            myOtherCar.Model = "98";

            Console.WriteLine("{0} {1} {2} {3}", myCar.Make, myCar.Model, myCar.Year, myCar.Color);

            myOtherCar = null;
            myCar      = null;

            Console.ReadLine();
        }
Example #2
0
        static void Main(string[] args)
        {
            Car myCar = new Car();    //myCar is holding the address of the object instance

            //"new Car();" in the computer's memory
            Car.MyMethod();



            myCar.Make  = "Jaguar";
            myCar.Model = "Sting-Ray";
            myCar.Year  = 2001;
            myCar.Color = "Silver";
            myCar.service(myCar.Year);

            /*
             * //Car myThirdCar = new Car("Audi", "Hydragin", 1997, "Red");  //assigning the values while instantiation of "myThirdCar"
             *
             *
             * //illiusion of the class with a object instance myAnotherCar
             * Car myOtherCar;        //Allocating a space(Handle) in memory without creating instance(Bucket) nothing but address
             * myOtherCar = myCar;       //copying the address to myAnotherCar from myCar(giving the power of myCar(created previously))
             * Console.WriteLine("Old Value");
             * Console.WriteLine("{0} {1} {2} {3}",
             *  myOtherCar.Make,
             *  myOtherCar.Model,
             *  myOtherCar.Year,
             *  myOtherCar.Color);
             *
             *
             * myOtherCar.Year = 1990;
             *
             * //first print
             * Console.WriteLine("New Value");
             * Console.WriteLine("{0} {1} {2} {3}",
             *  myCar.Make,
             *  myCar.Model,
             *  myCar.Year,
             *  myCar.Color);
             * //both are addressing same memory bucket "myAnotherCar" and "myCar"
             * //.NET framework library has garbage collection
             *
             *                                 //removing the reference myAnotherCar from
             *                               //the current metohd(cutting a string from a two string baloon);
             *                              //more deterministic way to handle references
             * //myOtherCar = null  //same as manual garbage collection as we don't know when .NET framework library will execute garbage collection process through the execution of program
             *
             * //Second print(Error will occur "System.NullReferenceException")
             *
             * Console.WriteLine("Old Value");
             *
             * Console.WriteLine("{0} {1} {2} {3}",
             *  myOtherCar.Make,
             *  myOtherCar.Model,
             *  myOtherCar.Year,
             *  myOtherCar.Color);
             *
             */
            Console.ReadLine();
        }
Example #3
0
        static void Main(string[] args)
        {
            Car myCar = new Car();

            Car.MyMethod();


            //myCar.Make = "Ford";
            //myCar.Model = "Focus";
            //myCar.Year = 1999;
            //myCar.Color = "silver";

            Car myOtherCar;

            myOtherCar = myCar;

            Console.WriteLine("{0} {1} {2} {3}", myOtherCar.Make,
                              myOtherCar.Model, myOtherCar.Year, myOtherCar.Color);

            myOtherCar.Model = "Mondeo";

            Console.WriteLine("{0} {1} {2} {3}", myCar.Make,
                              myCar.Model, myCar.Year, myCar.Color);

            myOtherCar = null; //reference panaikinimas

            //Console.WriteLine("{0} {1} {2} {3}", myOtherCar.Make,
            // myOtherCar.Model, myOtherCar.Year, myOtherCar.Color);

            //myCar = null;

            Car myThirdCar = new Car("Ford", "Escape", 2005, "White");

            Console.ReadLine();
        }
Example #4
0
        public static void Main(string[] args)
        {
            Car.MyMethod();
            Car myCar = new Car(); // calls the constructor when instantiated

            myCar.Make  = "Oldsmobile";
            myCar.Model = "Cutlas Supreme";
            myCar.Year  = 1986;
            myCar.Color = "Silver";

            Car myOtherCar; // both point to myCar.

            myOtherCar = myCar;

            Console.WriteLine("{0} {1} {2} {3}",
                              myOtherCar.Make,
                              myOtherCar.Model,
                              myOtherCar.Year,
                              myOtherCar.Color);
            // proof that it points to myCar's info.

            myOtherCar.Model = "98";

            Console.WriteLine("{0} {1} {2} {3}",
                              myCar.Make,
                              myCar.Model,
                              myCar.Year,
                              myCar.Color);
            // Model is now 98, since myOtherCar is a reference to myCar.

            myOtherCar = null; // sets both myOtherCar and myCar references to null

            Car myThirdCar = new Car("Ford", "Escape", 2005, "White");
            // Use of overloaded constructor.
        }
Example #5
0
        static void Main(string[] args)
        {
            Car myCar = new Car();

            //myCar.Make = "Audi";
            //myCar.Model = "A3";
            //myCar.Year = 2009;
            //myCar.Color = "Dark Green";

            Car.MyMethod();

            /*
             * //Car myThirdCar = new Car("Ford", "Fiesta", 2005, "White");
             *
             *
             * Car myOtherCar;
             * myOtherCar = myCar;
             *
             * Console.WriteLine("{0} {1} {2} {3}", myOtherCar.Make, myOtherCar.Model, myOtherCar.Year, myOtherCar.Color);
             * myOtherCar.Model = "A6";
             * Console.WriteLine("{0} {1} {2} {3}", myCar.Make, myCar.Model, myCar.Year, myCar.Color);
             *
             * myOtherCar = null;
             *
             * //Console.WriteLine("{0} {1} {2} {3}", myOtherCar.Make, myOtherCar.Model, myOtherCar.Year, myOtherCar.Color);
             *
             * myCar = null;
             */

            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            Car myCar = new Car();

            Car.MyMethod();

            // myCar.Make = "Oldmobile";
            // myCar.Model = "Cutlas Supreme";
            // myCar.Year = 1986;
            // myCar.Color = "Silver";

            // Car myOtherCar;
            // myOtherCar = myCar;

            // Console.WriteLine("{0} {1} {2} {3}",
            //     myCar.Make,
            //     myCar.Model,
            //     myCar.Year,
            //     myCar.Color);

            // myOtherCar.Model = "98";

            // myOtherCar = null;

            // Console.WriteLine("{0} {1} {2} {3}",
            //     myOtherCar.Make,
            //     myOtherCar.Model,
            //     myOtherCar.Year,
            //     myOtherCar.Color);

            Console.ReadLine();
        }
Example #7
0
        static void Main(string[] args)
        {
            Car myCar = new Car();

            Car.MyMethod();
            Console.WriteLine();

            /*
             * myCar.Make = "OldsMobile";
             * myCar.Model = "Cutlas Supreme";
             * myCar.Year = 1986;
             * myCar.Color = "Silver";
             */

            Car myThirdCar = new Car("Ford", "Escape", 2005, "White");

            Console.WriteLine("My third Card has these features: {0} {1} {2} {3}",
                              myThirdCar.Make,
                              myThirdCar.Model,
                              myThirdCar.Year,
                              myThirdCar.Color);
            Console.WriteLine();

            /*
             * Car myOtherCar;
             * myOtherCar = myCar;//myOtherCar is a variable that refers to the same memory address as myCar.
             *
             * Console.WriteLine("Variable myOtherCar points to same memory as myCar: {0} {1} {2} {3}",
             *  myOtherCar.Make,
             *  myOtherCar.Model,
             *  myOtherCar.Year,
             *  myOtherCar.Color);
             *
             * myOtherCar.Model = "98";//changing myCar.Model("Cutlas Supreme" to myOtherCar.Model ("98")
             * Console.WriteLine();
             * Console.WriteLine("Checking to see myOtherCar and myCar hold " +
             *  "same variable as they point to same memory:" + " " +
             *  "{0} {1} {2} {3}",
             *  myCar.Make,
             *  myCar.Model,
             *  myCar.Year,
             *  myCar.Color);
             * //setting myOtherCar object reference to null
             * myOtherCar = null;//null is not zero or empty but indeterminate
             * /*
             * Console.WriteLine("Variable myOtherCar points to same memory as myCar: {0} {1} {2} {3}",
             *  myOtherCar.Make,
             *  myOtherCar.Model,
             *  myOtherCar.Year,
             *  myOtherCar.Color);
             * //null reference exception unhandled will be thrown
             *
             *
             * //setting myCar object also as null and this removes all references to memory
             * myCar = null;
             */
            Console.ReadLine();
        }//this block ends the references to the two objects by releasing them from  memory or in other words the object goes out of scope after this block
Example #8
0
        public static void Main(string[] args)
        {
            //            Car myCar = new Car(/*calling the empty constructor method*/);
            //            // Make is set in constructor
            //            myCar.Make = "Pontiac";
            //            myCar.Model = "G6";
            //            myCar.Year = 2007;
            //            myCar.Color = "Black";

            // using the overloaded constructor
            Car myCar = new Car(
                "Pontiac",
                "G6",
                2007,
                "Black"
                );

            Car.MyMethod();

            Car myOtherCar;

            // both variable reference the same object
            // in memory
            myOtherCar = myCar;

            Console.WriteLine(
                "{0} {1} {2} {3}",
                myOtherCar.Make,
                myOtherCar.Model,
                myOtherCar.Year,
                myOtherCar.Color
                );

            // changing a property on one variable will be
            // reflected in the other variable, since they
            // both point to the same object in memory
            myOtherCar.Model = "G7";

            Console.WriteLine(
                "{0} {1} {2} {3}",
                myCar.Make,
                myCar.Model,
                myCar.Year,
                myCar.Color
                );

            // will throw an exception!
            //            myOtherCar = null;
            //            Console.WriteLine(
            //                "{0} {1} {2} {3}",
            //                myOtherCar.Make,
            //                myOtherCar.Model,
            //                myOtherCar.Year,
            //                myOtherCar.Color
            //            );

            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            Car myCar = new Car();

            Car.MyMethod();

            /*
             * myCar.Make = "Oldsmobile";
             * myCar.Model = "Cutlas Supreme";
             * myCar.Year = 1986;
             * myCar.Color = "Silver";
             */

            Car myThirdCar = new Car("Ford", "Escape", 2005, "White");

            Console.WriteLine("{0} {1} {2} {3}",
                              myThirdCar.Make,
                              myThirdCar.Model,
                              myThirdCar.Year,
                              myThirdCar.Color);

            Car myOtherCar;

            myOtherCar = myCar;

            Console.WriteLine("{0} {1} {2} {3}",
                              myOtherCar.Make,
                              myOtherCar.Model,
                              myOtherCar.Year,
                              myOtherCar.Color);

            myOtherCar.Model = "98";

            Console.WriteLine("{0} {1} {2} {3}",
                              myCar.Make,
                              myCar.Model,
                              myCar.Year,
                              myCar.Color);

            myOtherCar = null;

            /*
             * Console.WriteLine("{0} {1} {2} {3}",
             * myOtherCar.Make,
             * myOtherCar.Model,
             * myOtherCar.Year,
             * myOtherCar.Color);
             */

            myCar = null;

            Console.ReadLine();
        }
Example #10
0
        static void Main(string[] args)
        {
            Car myCar = new Car();

            // set properties

            Car myOtherCar = myCar;

            Car myThirdCar = new Car("Ford", "Escape", 2005, "White");

            //myOtherCar = null;
            //myCar = null;

            Car.MyMethod();
        }
Example #11
0
        static void Main(string[] args)
        {
            Car myCar = new Car();

            Car.MyMethod();

            /*
             * myCar.Make = "Oldsmobile";
             * myCar.Model = "Cutlas Supreme";
             * myCar.Year = 1986;
             * myCar.Color = "Silver";
             */

            Car myThirdCar = new Car("Ford", "Escape", 2005, "White");

            Car myOtherCar;

            myOtherCar = myCar;

            Console.WriteLine("{0} {1} {2} {3}",
                              myOtherCar.Make,
                              myOtherCar.Model,
                              myOtherCar.Year,
                              myOtherCar.Color);

            myOtherCar.Model = "98";

            Console.WriteLine("{0} {1} {2} {3}",
                              myCar.Make,
                              myCar.Model,
                              myCar.Year,
                              myCar.Color);

            myOtherCar = null;
            //code below will result in exception because we are trying to reference an object in memory
            //that no longer has the specified "handle" or pointer attached to it
            //because variable has been set to null

            /*
             * Console.WriteLine("{0} {1} {2} {3}",
             *  myOtherCar.Make,
             *  myOtherCar.Model,
             *  myOtherCar.Year,
             *  myOtherCar.Color);
             */

            Console.ReadLine();
        }
Example #12
0
        static void Main(string[] args)
        {
            //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            // Exercises in creating, manipulating, and destroying object references, etc
            //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

            // create new instance of class object then populate it's properties
            Car myCar = new Car(); // basically calling Car() to create a new instance of a Car class object

            myCar.Make  = "Oldsmobile";
            myCar.Model = "Cutlas Supreme";
            myCar.Year  = 1986;
            myCar.Color = "Silver";

            /* create a reference to the new myCar class object (adds 1 to the reference count in C#)
             * does not use the constructor since it is a reference to the first already constructed class object */
            Car myOtherCar = myCar;

            // change a property value of the new class object then display the properties of the new referenced class object (myOtherCar)
            myOtherCar.Make = "Mercedes-Benz";
            string strmyOtherCarProperties = string.Format("myOtherCar properties: {0} {1} {2} {3}", myOtherCar.Make, myOtherCar.Model, myOtherCar.Year, myOtherCar.Color);

            CreateTestOutput(strmyOtherCarProperties);

            /* now we display the property values of the original class object - note they are the same since mOtherCar points to the same class object
             * - it i imply a reference to the same class object */
            string strmyCarProperties = string.Format("myCar properties: {0} {1} {2} {3}", myCar.Make, myCar.Model, myCar.Year, myCar.Color);

            CreateTestOutput(strmyCarProperties);

            // call overloaded method and pass variables then display properties
            Car    myThirdCar = new Car("Ford", "Explorer", 1989, "Blue");
            string strmyThirdCarProperties = string.Format("myCar properties: {0} {1} {2} {3}", myThirdCar.Make, myThirdCar.Model, myThirdCar.Year, myThirdCar.Color);

            CreateTestOutput(strmyThirdCarProperties);

            // static methods in classes

            /* call static method in Car class (static methods in classes do not require us to instantiate  or create a new class object
             * - we can simply call them - no need for a new instance of the Car class */
            Car.MyMethod();

            // close references to the objects
            myOtherCar = null;
            myCar      = null;
        }
Example #13
0
        static void Main(string[] args)
        {
            Car myCar = new Car();

            Car.MyMethod();

            /*
             * myCar.Make = "Oldsmobile";
             * myCar.Model = "Cutlas Supreme";
             * myCar.Year = 1986;
             * myCar.Color = "Silver";
             */

            Car myThirdCar = new Car("Jeep", "Thunder", 1969, "Yellow");

            Car myOtherCar;

            myOtherCar = myCar;

            Console.WriteLine("{0} {1} {2} {3}",
                              myOtherCar.Make,
                              myOtherCar.Model,
                              myOtherCar.Year,
                              myOtherCar.Color);

            myOtherCar.Model = "Accord";

            Console.WriteLine("{0} {1} {2} {3}",
                              myCar.Make,
                              myCar.Model,
                              myCar.Year,
                              myCar.Color);

            //myOtherCar = null;
            myCar = null;
            // "deterministic finalization" approach to garbage collection

            Console.WriteLine("{0} {1} {2} {3}",
                              myOtherCar.Make,
                              myOtherCar.Model,
                              myOtherCar.Year,
                              myOtherCar.Color);

            Console.ReadLine();
        }
Example #14
0
        static void Main(string[] args)
        {
            Car myCar = new Car();

            Car.MyMethod();

            /*
             * myCar.Make = "Oldmobile";
             * myCar.Model = "Cutlas Supreme";
             * myCar.Year = 1986;
             * myCar.Color = "Silver";
             *
             *
             * Car myThirdCar = new Car("Hyundai", "Accent", 2013, "Desert Blonde");
             *
             * Car myOtherCar = myCar;
             * myOtherCar = myCar;
             *
             * Console.WriteLine("{0} {1} {2} {3}",
             *  myOtherCar.Make,
             *  myOtherCar.Model,
             *  myOtherCar.Year,
             *  myOtherCar.Color);
             *
             * //this updates myCar also.
             * myOtherCar.Model = "98";
             *
             * Console.WriteLine("{0} {1} {2} {3}",
             *  myCar.Make,
             *  myCar.Model,
             *  myCar.Year,
             *  myCar.Color);
             *
             * Console.WriteLine("{0} {1} {2} {3}",
             *  myOtherCar.Make,
             *  myOtherCar.Model,
             *  myOtherCar.Year,
             *  myOtherCar.Color);
             *
             *
             * myCar = null;
             */

            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            Car myCar = new Car("Honda", "Japan", 1992, "red");

            Car myOtherCar;

            myOtherCar = myCar;                  //references the same object
            Console.WriteLine(myOtherCar.Color); //red
            myOtherCar.Color = "blue";
            Console.WriteLine(myCar.Color);      //now it's blue

            Car.MyMethod();

            //myOtherCar = null; //remove one reference
            //myCar = null; //removed all references. object will be removed in some unknown time

            Console.ReadLine();
        }
Example #16
0
        static void Main(string[] args)
        {
            //Car myCar = new Car();

            Car.MyMethod();

            //myCar.Make = "Oldsmobile";
            //myCar.Model = "Cutlas Supreme";
            //myCar.Year = 1986;
            //myCar.Color = "Silver";

            //Car myOtherCar;
            //myOtherCar = myCar;

            //Car myThirdCar = new Car("Ford", "Escape", 2005, "White");

            //Console.WriteLine("{0} {1} {2} {3}",
            //    myOtherCar.Make,
            //    myOtherCar.Model,
            //    myOtherCar.Year,
            //    myOtherCar.Color);

            //myOtherCar.Model = "98";

            //Console.WriteLine("{0} {1} {2} {3}",
            //    myCar.Make,
            //    myCar.Model,
            //    myCar.Year,
            //    myCar.Color);

            //myOtherCar = null;

            //Causes an exception because myOtherCar is no longer a reference
            //Console.WriteLine("{0} {1} {2} {3}",
            //    myOtherCar.Make,
            //    myOtherCar.Model,
            //    myOtherCar.Year,
            //    myOtherCar.Color);

            //myCar = null;


            Console.ReadLine();
        }
Example #17
0
        static void Main(string[] args)
        {
            Car myCar = new Car();

            Car.MyMethod();

            /*myCar.Color = "Black";
             * myCar.Year = 2012;
             * myCar.Make = "Toyota";
             * myCar.Model = "Tundra";
             *
             * //Car myThirdCar = new Car("Grey", 2017, "Chevrolet", "Bolt");
             *
             * Car myOtherCar;
             * myOtherCar = myCar;
             *
             * Console.WriteLine("{0} {1} {2} {3}",
             *  myOtherCar.Color,
             *  myOtherCar.Year,
             *  myOtherCar.Make,
             *  myOtherCar.Model);
             *
             * myOtherCar.Model = "Tacoma";
             *
             * Console.WriteLine("{0} {1} {2} {3}",
             * myCar.Color,
             * myCar.Year,
             * myCar.Make,
             * myCar.Model);
             *
             * myOtherCar = null;
             *
             * //Throws exception because myOtherCar is no longer living at the address (bucket handle was broken, or whatever analogy fits)
             * Console.WriteLine("{0} {1} {2} {3}",
             *  myOtherCar.Color,
             *  myOtherCar.Year,
             *  myOtherCar.Make,
             *  myOtherCar.Model);
             *
             * myCar = null;*/

            Console.ReadLine();
        }
Example #18
0
        // static classes will available to you without requiring you create an instance of a class
        // Constructors are method that allow us to write code at the moment when the class is being created
        public static void Main(string[] args)
        {
            // mycar only exist within the main method, it can not be reference outside main method
            Car myCar = new Car();

            Car.MyMethod();

            /*
             * myCar.Make = "Oldmobile";
             * myCar.Model = "Cutlas Supreme";
             * myCar.Year = 1986;
             * myCar.Colour = "Silver";
             *
             *
             * // create a "handle" but not attached to any "buckets" of cars in our memory
             * Car myOtherCar;
             *
             * // copies the address of myCar so uses the same attributes
             * myOtherCar = myCar;
             *
             * //Car myThirdCar = new Car ("Bugatti", "Super Sport", 2015, "Red");
             *
             * Console.WriteLine ("{0} {1} {2} {3}", myOtherCar.Make, myOtherCar.Model, myOtherCar.Year, myOtherCar.Colour);
             *
             * //Changing attributes from myOther car
             * myOtherCar.Model = "98";
             *
             * Console.WriteLine ("{0} {1} {2} {3}", myCar.Make, myCar.Model, myCar.Year, myCar.Colour);
             *
             * // remove one of the handle to the bucket. Which causes a handle exception
             * myOtherCar = null;
             *
             * //Console.WriteLine ("{0} {1} {2} {3}", myOtherCar.Colour, myOtherCar.Make, myOtherCar.Model, myOtherCar.Year);
             *
             * //References are gone completly
             * myCar = null;
             *
             * Console.WriteLine ("{0} {1} {2} {3}", myThirdCar.Make, myThirdCar.Model, myThirdCar.Year, myThirdCar.Colour);
             */
            Console.ReadLine();
        }
Example #19
0
        static void Main(string[] args)
        {
            Car myCar = new Car();

            myCar.Make  = "Oldmobile";
            myCar.Model = "Cutlas Supreme";
            myCar.Year  = 1986;
            myCar.Color = "Silver";

            // Coping the address (so 2 objs point to the same address)
            Car myOtherCar;

            myOtherCar = myCar;
            Console.WriteLine("{0} {1} {2} {3}", myOtherCar.Make,
                              myOtherCar.Model, myOtherCar.Year, myOtherCar.Color);

            myOtherCar.Model = "98";
            Console.WriteLine("{0} {1} {2} {3}", myCar.Make,
                              myCar.Model, myCar.Year, myCar.Color);

            // Remove the reference to the second obj from memory
            myOtherCar = null;

            // Check a constructor
            Car myNewCar = new Car();

            Console.WriteLine("{0} {1} {2} {3}", myNewCar.Make,
                              myNewCar.Model, myNewCar.Year, myNewCar.Color);

            Car myThirdCar = new Car("Ford", "Escape", 2005, "White");

            Console.WriteLine("{0} {1} {2} {3}", myThirdCar.Make,
                              myThirdCar.Model, myThirdCar.Year, myThirdCar.Color);

            // Static methods vs instance methods
            Car.MyMethod();
            // You can create static class and all its method become static too!

            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            Car myCar = new Car();

            Car.MyMethod();     // Explication of "static" using my own method.

            /*
             * myCar.Make = "oldmobile";
             * myCar.Model = "Cutlas Supreme";          // Bad way to create a object.
             * myCar.Year = 1986;
             * myCar.Color = "Silver";
             */

            // This is how creates a top object using the construct.
            //Car myThirdCar = new Car("Ford", "Escape", 2005, "White");

            Car myOtherCar;

            myOtherCar = myCar;     //    When I created a new object and said that they
                                    // were the same, myCar assumed myOtherCar and vice-versa.

            Console.WriteLine("{0} {1} {2} {3}",
                              myOtherCar.Make,
                              myOtherCar.Model,
                              myOtherCar.Year,
                              myOtherCar.Color);

            myOtherCar.Model = "98";

            Console.WriteLine("{0} {1} {2} {3}",
                              myCar.Make,
                              myCar.Model,
                              myCar.Year,
                              myCar.Color);

            myOtherCar = null;
            myCar      = null;

            Console.ReadLine();
        }
Example #21
0
        static void Main(string[] args)
        {
            Car myCar = new Car();

            Car.MyMethod();

            /*
             * myCar.Make = "Nissan";
             * myCar.Model = "Skyline";
             * myCar.Year = 1998;
             * myCar.Color = "Gunmetal Gray";
             */

            Car myThirdCar = new Car("Nissan", "GTR", 2018, "Black");

            Console.WriteLine("{0} {1} {2} {3}",
                              myCar.Make,
                              myCar.Model,
                              myCar.Year,
                              myCar.Color);
            Console.ReadLine();
        }
Example #22
0
        public static void Main(string[] args)
        {
            Car myCar = new Car();

            /*myCar.Make = "Bugatti";
             * myCar.Model = "Highballer";
             * myCar.Year = 2018;
             * myCar.Color = "Crimson";*/

            Car myOtherCar;

            myOtherCar = myCar;             // Adding another access point to the same specific space in memory

            Console.WriteLine("{0} {1} {2} {3}", myOtherCar.Make, myOtherCar.Model,
                              myOtherCar.Year, myOtherCar.Color); //proving that their the same access point

            myOtherCar = null;                                    // Removes this access point to the specific space in memory

            Car myBestCar = new Car("Toyota", "Camry", 2012, "Royal Blue");

            Car.MyMethod();
        }
        // static keyword: you dont need to create an intance of the class in order to utilize its method and properties
        static void Main(string[] args)
        {
            Car myCar = new Car();

            /*
             * myCar.Make = "Honda";
             * myCar.Model = "Civic";
             * myCar.Year = 2008;
             * myCar.Color = "Red";
             */

            Car myOtherCar;

            myOtherCar = myCar;

            Console.WriteLine("{0} {1} {2} {3}",
                              myOtherCar.Make,
                              myOtherCar.Model,
                              myOtherCar.Year,
                              myOtherCar.Color);

            myOtherCar.Model = "Clarity";

            Console.WriteLine("{0} {1} {2} {3}",
                              myCar.Make, myCar.Model, myCar.Year, myCar.Color);

            // when you set references to null or move out of scope, the .NET framework will do its garbage collection
            // myOtherCar = null;
            // myCar = null;

            Car myThirdCar = new Car("Bettle", "Princess", 2010, "Yellow");

            // notice: since MyMethod is a static method in Car class, you don't need to create an intance to call it
            Car.MyMethod();
            // make sure to check if you're working with 'static members' or 'instance members' of the class

            Console.ReadLine();
        }
Example #24
0
        public static void Main(string[] args)
        {
            Car myCar = new Car();

            Car.MyMethod();

            //myCar.Make = "Ford";
            //myCar.Model = "F150";
            //myCar.Year = 2013;
            //myCar.Color = "Black";

            //Car myThirdCar = new Car("Dodge", "Viper", 2006, "Red");

            //Car myOtherCar;
            //myOtherCar = myCar;

            //Console.WriteLine("{0} {1} {2} {3}",
            //                  myOtherCar.Make,
            //                  myOtherCar.Model,
            //                  myOtherCar.Year,
            //                  myOtherCar.Color);


            //myOtherCar.Model = "98";

            //Console.WriteLine("{0} {1} {2} {3}",
            //                  myCar.Make,
            //                  myCar.Model,
            //                  myCar.Year,
            //                  myCar.Color);

            //myOtherCar = null;

            //myCar = null;


            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            Car myCar = new Car();

            Car.MyMethod();
Example #26
0
        static void Main(string[] args)
        {
            Car myCar = new Car();

            /*
             * myCar.Make = "Oldsmobile";
             * myCar.Model = "Cutlass Supreme";
             * myCar.Year = 1986;
             * myCar.Color = "Silver";
             *
             * /////////////////////////////////////////////////////
             *
             * Car myOtherCar;
             * myOtherCar = myCar;
             *
             * Console.WriteLine("{0} {1} {2} {3}",
             *  myOtherCar.Make, myOtherCar.Model,
             *  myOtherCar.Year.ToString(), myOtherCar.Color);
             *
             * /////////////////////////////////////////////////////
             *
             * // the 98 changes the original because it is a pointer
             * myOtherCar.Model = "98";
             *
             * Console.WriteLine("{0} {1} {2} {3}",
             *  myOtherCar.Make, myOtherCar.Model,
             *  myOtherCar.Year.ToString(), myOtherCar.Color);
             *
             * Console.WriteLine("{0} {1} {2} {3}",
             *  myCar.Make, myCar.Model, myCar.Year.ToString(), myCar.Color);
             *
             * /////////////////////////////////////////////////////
             *
             * // This removes the pointer
             *
             * myOtherCar = null;
             *
             * // if you tried to print this again, it would cause exception
             *
             * /////////////////////////////////////////////////////
             *
             * // removes remaining reference to data
             * // eventually garbage collector will pick this up
             *
             * // you can also tell .NET to do it now
             * // this is called deterministic finalization
             *
             * myCar = null;
             *
             */
            /////////////////////////////////////////////////////

            // this display is to show that the constructor is working.
            // the code above this was mostly commented out

            Console.WriteLine("{0} {1} {2} {3}",
                              myCar.Make, myCar.Model, myCar.Year.ToString(), myCar.Color);

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

            Car myThirdCar = new Car("Ford", "Escape", 2005, "White");

            Console.WriteLine("{0} {1} {2} {3}",
                              myThirdCar.Make, myThirdCar.Model,
                              myThirdCar.Year.ToString(), myThirdCar.Color);

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

            Car.MyMethod();

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

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

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

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

            Console.ReadLine();
        }