static void Main(string[] args) { Car myCar = new Car(); //myCar.Make = "oldsmobile"; //myCar.Model = "cutlas supreme"; //myCar.Year = 1986; //myCar.Color = "Silver"; 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; Car myThirdCar = new Car("Ford", "Escape", 2005, "white"); Console.WriteLine("{0} {1} {2} {3}", myThirdCar.Make, myThirdCar.Model, myThirdCar.Year, myThirdCar.Color); //Use the static car method Car.MyMethod(); }
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", "Escape", 205, "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; * * 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 myThirdCar = new Car("Ford", "Escape", 2005, "White"); //We can do this due to line 86 /* * 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; * * //this will not word because we have removed the access for myOtherCar * //null means indeterminate, not zero , not an empty string. Meaning its undefine. * Console.WriteLine("{0} {1} {2} {3}", * myOtherCar.Make, * myOtherCar.Model, * myOtherCar.Year, * myOtherCar.Color); * * * myCar = null; * // we have removed all the references. Becareful when you want to remove references * //because it could hold important references. * //The references may be have been removed but there are still memory inside. * //So its not removed completely. * */ Console.ReadLine(); }