static void Main(string[] args) { Console.WriteLine("Welcome to the Product Manager App"); Product p1 = new Product("java", "Murach's Java Programming", 59.50); Product p2 = new Product { Code = "c#", Description = "Murach's C# Programming", Price = 57.50 }; String c = MyConsole.GetString("Code: "); String d = MyConsole.GetString("Description: "); double p = MyConsole.GetDouble("Price: "); Product p3 = new Product(c, d, p); Product[] products = { p1, p2, p3 }; foreach (Product pdt in products) { Console.WriteLine(pdt); } Console.WriteLine(products[2]); //ArrayList productsList = new ArrayList(); List <Product> productsList = new List <Product>(); productsList.Add(p1); productsList.Add(p2); productsList.Add(p3); Console.WriteLine("ArrayList of products..."); foreach (Product pdt in productsList) { Console.WriteLine(pdt); } Product product = productsList[1]; Console.WriteLine("Using a Dictionary to store products..."); Dictionary <string, Product> productsMap = new Dictionary <string, Product>(); productsMap.Add(p1.Code, p1); productsMap.Add(p2.Code, p2); productsMap.Add(p3.Code, p3); string code = MyConsole.GetString("Enter product code to look up: "); Console.WriteLine("Product = " + productsMap[code]); productsMap.Remove(code); Console.WriteLine("Bye"); }
static void Main(string[] args) { Console.WriteLine("Welcome to the Product manager"); Product p1 = new Product("java", "java programming", 59.50); Product p2 = new Product { Code = "c#", Description = "Murach's Java Programming", Price = 57.50 }; Product p3 = new Product("mysql", "mysql programming", 19.99); Product[] products = { p1, p2, p3 }; foreach (Product pdt in products) { Console.WriteLine(pdt); } Console.WriteLine(products[2]); List <Product> productsList = new List <Product> { p1, p2, p3 }; Console.WriteLine("array list version of listing products"); foreach (Product pdt in productsList) { Console.WriteLine(pdt); } Console.WriteLine("using a dictionary to store products"); Dictionary <string, Product> productsMap = new Dictionary <string, Product>(); productsMap.Add(p1.Code, p1); productsMap.Add(p2.Code, p2); productsMap.Add(p3.Code, p3); string code = MyConsole.getString("Enter product code to look up: "); Console.WriteLine("Product = " + productsMap[code]); Console.WriteLine("bye"); }
static void Main(string[] args) { Console.WriteLine("Welcome to the Product Manager App"); Product p1 = new Product("java", "Murach's Java Programming", 59.50); Product p2 = new Product { Code = "C#", Description = "Murach's C# Programming", Price = 57.50 }; String c = MyConsole.GetString("Code: "); String d = MyConsole.GetString("Description: "); double p = MyConsole.GetDouble("Price: "); Product p3 = new Product(c, d, p); Product[] products = { p1, p2, p3 }; foreach (Product pdt in products) { Console.WriteLine(pdt); } Console.WriteLine(products[2]); //ArrayList productsList = new ArrayList(); //type "using System.Collections;" at top List <Product> productsList = new List <Product>(); //System.Collections.Generic; productsList.Add(p1); productsList.Add(p2); productsList.Add(p3); Console.WriteLine("ArrayList of products..."); foreach (Product pdt in productsList) { Console.WriteLine(pdt); } Product product = productsList[1]; Console.WriteLine(product); Console.WriteLine("Using a Dictionary to store products..."); Dictionary <string, Product> productsMap = new Dictionary <string, Product>(); productsMap.Add(p1.Code, p1); productsMap.Add(p2.Code, p2); productsMap.Add(p3.Code, p3); string code = MyConsole.GetString("Enter product code to look up: "); Console.WriteLine("Product = " + productsMap[code]); /*Console.WriteLine("p1: " + p1); * Console.WriteLine("p2: " + p2); * * String a = MyConsole.GetString("Enter a string: "); * Console.WriteLine("String = "+a); * * int i = MyConsole.GetInt("Enter an int: "); * Console.WriteLine("Int = "+i); * * double d = MyConsole.GetDouble("Enter a double: "); * Console.WriteLine("Double = "+d);*/ Console.WriteLine("Goodbye"); }