Пример #1
0
 protected Product createProduct(string type, string name, int price, int size)
 {
     if (type == "CD")
     {
         Product product = new CDProducts(name, price, size);
         return(product);
     }
     else if (type == "Book")
     {
         Product product = new BookProducts(name, price, size);
         return(product);
     }
     throw new ArgumentException($"Invalid argument: {type}");
 }
Пример #2
0
        public string listProducts()
        {
            string productsList = "";

            foreach (Product product in storage.GetAllProduct)
            {
                if (product.GetType() == typeof(CDProducts))
                {
                    CDProducts cdproduct = (CDProducts)product;
                    productsList += cdproduct.ToString() + "\n";
                }
                else if (product.GetType() == typeof(BookProducts))
                {
                    BookProducts bookproduct = (BookProducts)product;
                    productsList += bookproduct.ToString() + "\n";
                }
            }
            return(productsList);
        }