static void Main(string[] args) { Console.WriteLine("***** Fun with Automatic Properties *****\n"); Car c = new Car(); c.PetName = "Frank"; c.Speed = 55; c.Color = "Red"; Console.WriteLine("Your car is named {0}? That's odd...", c.PetName); c.DisplayStats(); Garage g = new Garage(); // OK, prints default value of zero. Console.WriteLine("Number of Cars: {0}", g.NumberOfCars); // Runtime error! Backing field is currently null! //Console.WriteLine(g.MyAuto.PetName); g.MyAuto = c; Console.WriteLine("Number of Cars in garage: {0}", g.NumberOfCars); Console.WriteLine("Your car is named: {0}", g.MyAuto.PetName); }
static void Main(string[] args) { Console.WriteLine("***** Fun with Automatic Properties *****\n"); // make a Car instance Car c = new Car { // per IDE suggestion: Instantiate object in one code set instead of line-by-line PetName = "Frank", Speed = 55, Color = "Red" }; Console.WriteLine($"Your car is named {c.PetName}? That's odd..."); c.DisplayStats(); Console.WriteLine("\n\n"); // put Car instance in the garage Garage g = new Garage { MyAuto = c }; // Prints default value of zero: Console.WriteLine($"Number of Cars in garage: {g.NumberOfCars}"); // Runtime error when backing field is currently null (fixed by adding a Constructor to Garage class Console.WriteLine($"Your car is named: {g.MyAuto.PetName}"); Console.ReadLine(); }
static void Main(string[] args) { Console.WriteLine("***** Fun with Automatic Properties *****\n"); // Make a car. Car lonelyCar = new Car(); lonelyCar.Name = "Ford"; lonelyCar.Speed = 55; lonelyCar.Color = "Red"; lonelyCar.DisplayStats(); // here is another way using Automatic Properties (or AutoProps) Car anotherCar = new Car() { Name = "BMW", Speed = 60, Color = "Black", }; anotherCar.DisplayStats(); // Put car in the garage. Garage myGarage = new Garage(lonelyCar, 4); myGarage.MyAuto = anotherCar; Console.WriteLine("Number of Cars in garage: {0}", myGarage.NumberOfCars); Console.WriteLine("Your car is named: {0}", myGarage.MyAuto.Name); Console.ReadLine(); }
static void Main(string[] args) { Car c = new Car("Frank", 50, "red"); c.DisplayStats(); Garage g = new Garage(); Console.WriteLine("=> auto properies are initialized to defaults"); Console.WriteLine("int: {0}", g.NumberOfCars); Console.WriteLine("object is null {0}", g.MyAuto == null); Console.ReadLine(); }
static void Main(string[] args) { Console.WriteLine("**** Fun with Automatic properties****\n"); Car c = new Car(); c.PetName = "Frank"; c.Speed = 55; c.Color = "Red"; Console.WriteLine(" Your car is named {0}? Thath's odd...", c.PetName); c.DisplayStats(); Console.ReadLine(); }
static void Main(string[] args) { Console.WriteLine("Fun With Automatic Properties****\n"); Car Car = new Car(); Car.petName = "Frank"; Car.Speed = 55; Car.Color = "Blue"; Console.WriteLine("Your car is named {0}? That s odd...", Car.petName); Car.DisplayStats(); Console.ReadLine(); }
static void Main(string[] args) { Car c = new Car(); c.PetName = "Frank"; c.Speed = 55; c.Color = "red"; Console.WriteLine("your car is named:{0}",c.PetName); c.DisplayStats(); Garage g = new Garage(); g.myAuto = c; Console.WriteLine("Number of cars:{0}",g.NumberOfCars); Console.WriteLine(g.myAuto.PetName); Console.ReadLine(); }
private static void Main(string[] args) { Console.WriteLine("***** Fun With Automatic Properties *****"); var car = new Car("LADA", 55, "Red"); car.DisplayStats(); Console.ReadLine(); var g = new Garage(); g.MyAuto = car; Console.WriteLine("Number of Cars in Garage: {0}", g.NumberOfCar); Console.WriteLine("Name of My Car in Garage: {0}", g.MyAuto.PetName); Console.ReadLine(); }
static void Main(string[] args) { Console.WriteLine("***** Fun with Automatic Properties *****\n"); Car c = new Car(); c.PetName = "Frank"; c.Speed = 55; c.Color = "Red"; Console.WriteLine("Your car is named {0}? That's odd...", c.PetName); c.DisplayStats(); // Put car in the garage. Garage g = new Garage(); g.MyAuto = c; Console.WriteLine("Number of Cars in garage: {0}", g.NumberOfCars); Console.WriteLine("Your car is named: {0}", g.MyAuto.PetName); Console.ReadLine(); }
static void Main(string[] args) { Console.WriteLine("**** Fun with automatic props ****"); Car c = new Car(); c.PetName = "Frank"; c.Speed = 23; c.Color = "Red"; Console.WriteLine("Your car name is {0}? That's odd...", c.PetName); c.DisplayStats(); Console.WriteLine(); Garage g = new Garage(); g.MyAuto = c; Console.WriteLine("Number of cars: {0}", g.NumberOfCars); Console.WriteLine("My car's name: {0}", g.MyAuto.PetName); Console.ReadLine(); }
static void Main(string[] args) { Console.WriteLine("***** Fun with Automatic Properties *****\n"); Car c = new Car(); c.PetName = "Frank"; c.Speed = 55; c.Color = "Red"; Console.WriteLine("Your car is named {0}? That's odd...", c.PetName); c.DisplayStats(); Garage g = new Garage(); g.MyAuto = c; Console.WriteLine("Number Of Cars in garage: {0}", g.NumberOfCars); Console.WriteLine("Your car is named: {0}", g.MyAuto.PetName); Console.ReadLine(); }
static void Main(string[] args) { Console.WriteLine("*** Testing Auto properties ***"); Car c = new Car(); c.PetName = "Frank"; c.Speed = 45; c.Color = "Blue"; Console.WriteLine("Your car is named {0}", c.PetName); c.DisplayStats(); //Put car in the garage Garage g = new Garage(); g.MyAuto = c; Console.WriteLine("NofCars inside: {0}", g.NumberOfCars); Console.WriteLine("Ur car is: {0}", g.MyAuto.PetName); }
static void Main(string[] args) { Console.WriteLine("***** Fun with Automatic Properties *****\n"); // Make a car. Car c = new Car(); c.PetName = "Frank"; c.Speed = 55; c.Color = "Red"; c.DisplayStats(); // Put car in the garage. Garage g = new Garage(); g.MyAuto = c; Console.WriteLine("Number of Cars in garage: {0}", g.NumberOfCars); Console.WriteLine("Your car is named: {0}", g.MyAuto.PetName); // lets dispose it g.Dispose(); Console.ReadLine(); }
static void Main(string[] args) { Console.WriteLine("***** Fun with auto props *****\n"); Car c = new Car(); c.PetName = "Frank"; c.Speed = 55; c.Color = "Red"; //Console.WriteLine("Your car is named {0}? That's odd...",c.PetName); c.DisplayStats(); //put car in the garage. Garage g = new Garage(); g.MyAuto = c; //0OK, prints default value of 0. Console.WriteLine("Number of cars in garage: {0}", g.NumberOfCars); Console.WriteLine("Your car is named: {0}", g.MyAuto.PetName); //runtime error! backing field is currently null! //Console.WriteLine(g.MyAuto.PetName); Console.ReadLine(); }
private static void Main(string[] args) { Console.WriteLine("***** Fun with Automatic Properties *****\n"); var c = new Car() { PetName = "Frank", Speed = 55, Color = "Red" }; Console.WriteLine("Your car is named {0}? That't odd...", c.PetName); c.DisplayStats(); var g = new Garage() { MyAuto = c }; Console.WriteLine("Number of Cars: {0}", g.NumberOfCars); Console.WriteLine("Your car is named: {0}", g.MyAuto.PetName); Console.ReadLine(); }