public void SetMeasurementsForProduct(Product product, float height, float width, float depth) { //C# 5.0 if (product != null && product.Measurement != null) { product.Measurement.SetMeasurements(height,width,depth); } //C# 6.0 product?.Measurement?.SetMeasurements(height,width,depth); }
public string GetBuyerOfProduct(Product product) { string result = null; //C# 5.0 result = string.Format("{0} {1} bought {2}", _firstname, _name, product.Name); //C# 6.0 result = $"{_firstname} {_name} bought {product?.Name}"; return result; }
public string GetStockOfProduct(Product product) { string result = null; //C# 5.0 result = string.Format("There are {0} {1}{2} left", product.Stock, product.Name, product.Stock > 1 ? "s" : ""); //C# 6.0 result = $"There are {product?.Stock} {product?.Name}{(product?.Stock > 1 ? "s" : "")}"; return result; }
public string GetMeasurementsOfProduct(Product product) { string result = null; //C# 5.0 result = string.Format("{0} measurements: height: {1:D2}, width: {2:D2}, depth: {3:D2}", product.Name, product.Measurement.Heigth, product.Measurement.Width, product.Measurement.Depth); //C# 6.0 result = $"{product?.Name} measurements: height: {product?.Measurement?.Heigth:D2}, width: {product?.Measurement.Width:D2}, depth: {product?.Measurement.Depth:D2}"; return result; }
public string GetProductName(Product product) { string name = null; //C# 5.0 if (product != null) { name = product.Name; } //C# 6.0 name = product?.Name; return name; }
public void SetCategoryForProduct(Product prodcut, Category? category) { if(category == null) throw new ArgumentNullException($"Arguemnt {nameof(category)} is null"); }