public ViewResult UsingExtenionMethodsPart1() { ShoppingCart cart = new ShoppingCart() { Laptops = Laptop.GetLaptops() }; // If we didn't cast the result to object, the following code will be go to the view with the of the result :) return(View((object)string.Format($"The price will be {cart.TotalPrices()}"))); }
public ViewResult AutoImplementedPropertyInitializer() { List <String> list = new List <string>(); foreach (var laptop in Laptop.GetLaptops()) { string Brand = laptop?.Brand ?? "<No Brand>"; string Model = laptop?.Model ?? "<No Model>"; decimal?Price = laptop?.Price ?? 0M; string Category = laptop?.Category ?? "<No Category>"; bool InStock = laptop?.InStock ?? false; list.Add(string.Format($"{nameof(Brand)}: {Brand}, " + $"{nameof(Model)}: {Model}, " + $"{nameof(Price)}: {Price}, " + $"{nameof(Category)}: {Category}, " + $"{nameof(InStock)}: {InStock}" )); } return(View(list)); }