static void Main(string[] args) { Console.WriteLine("Welcome to the Antique Shop!"); // Advised to use decimal for monetary amounts and must use "m" at // the end of decimal amount as on line 15 below AntiqueItem chair = new AntiqueItem() { Name = "An old chair", Price = 45.50m, }; AntiqueItem vase = new AntiqueItem() { Name = "A priceless vase", Price = 1.00m, }; AntiqueItem painting = new AntiqueItem(); painting.Name = "Washington on a Horse"; painting.Price = 100.99m; Customer alice = new Customer("Alice", "Jones", 10m, 100m); alice.ExamineItem(chair); alice.ExamineItem(vase); alice.ExamineItem(painting); }
static void Main(string[] args) { Console.WriteLine("Welcome to the Antique Shoppe!"); AntiqueItem chair = new AntiqueItem() { Name = "An old chair", Price = 45.50m, }; AntiqueItem vase = new AntiqueItem() { Name = "A priceless vase", Price = 1.00m, }; AntiqueItem painting = new AntiqueItem(); painting.Name = "Washington on a Horse"; painting.Price = 100.99m; Customer alice = new Customer("Alice", "Jones", 10m, 100m); alice.ExamineItem(chair); alice.ExamineItem(vase); alice.ExamineItem(painting); }
public void ExamineItem(AntiqueItem item) { if (item.Price >= _minPrice && item.Price < _maxPrice) { Console.WriteLine($"Would add {item.Name} to purchase list"); } else if (item.Price >= _maxPrice) { Console.WriteLine($"Would add {item.Name} to wish list"); } }
public void ExamineItem(AntiqueItem item) { if (item.Price >= _minPrice && item.Price < _maxPrice) { _purchaseList.Add(item); } else if (item.Price >= _maxPrice) { _wishList.Add(item); } }
// Method // A function defined in a class // Is some kind of "action" (aka "operation") // Provided behavior for an object // Naming convention = uppercase Pascalcase; // Remember parameters are lowercase / camelCase public void ExamineItem(AntiqueItem item) { if (item.Price >= _minPrice && item.Price < _maxPrice) { // CTRL + . to access System or click the light bulb on left side if there Console.WriteLine($"Would add {item.Name} to purchase list"); } else if (item.Price >= _maxPrice) { Console.WriteLine($"Would add {item.Name} to wish list"); } }
static void Main(string[] args) { Console.WriteLine("Welcome to the Antique Shoppe"); // Instanciate - Instance of something // Make that object and put it in a variable. AntiqueItem chair = new AntiqueItem() { // Object initialization syntax // m after number to specify it's a decimal type Name = "An old chair", Price = 45.50m, }; AntiqueItem vase = new AntiqueItem() { Name = "A priceless vase", Price = 1.00m }; AntiqueItem painting = new AntiqueItem(); painting.Name = "Washington on a Cow"; painting.Price = 100.99m; // Need to pass values to a contructor Customer alice = new Customer("Alice", "Jones", 10m, 100m); Console.WriteLine(alice.FullName); // An error on _minPrice because that field is private // decimal x = alice._minPrice; // Methods and passing in the argument alice.ExamineItem(chair); alice.ExamineItem(vase); alice.ExamineItem(painting); }
static List <AntiqueItem> GetAntiqueItems() { // NOTE: This code shows multiple ways to set properties and to add items to a list // In a real app you SHOULD BE CONSISTENT AntiqueItem chair = new AntiqueItem() { Name = "An old chair", Price = 45.50m, }; AntiqueItem vase = new AntiqueItem() { Name = "A priceless vase", Price = 1.00m }; AntiqueItem painting = new AntiqueItem(); painting.Name = "Washington on a Horse"; painting.Price = 100.99m; List <AntiqueItem> items = new List <AntiqueItem>() { chair, vase, painting }; items.Add(new AntiqueItem() { Name = "Snuff box", Price = 70.00m, }); items.Add(new AntiqueItem() { Name = "Some old Diamond", Price = 1_000_000m, });