public static void StructsArrayExample() { Console.Write("How many products would you like to enter?"); var n = int.Parse(Console.ReadLine()); Console.Write("Please enter {0} prdocuts information,", n); Product2[] products = new Product2[n]; for (int i = 0; i < n; i++) { products[i] = new Product2(); Console.Write("Enter Code: "); products[i].Code = Console.ReadLine(); Console.Write("Enter Name: "); products[i].Name = Console.ReadLine(); Console.Write("Enter Price: "); products[i].Price = decimal.Parse(Console.ReadLine()); } Console.WriteLine("\nThe following products are entered:"); foreach (var p in products) { p.Show(); } }
public static void Example2() { var p = new Product2("C102", "Mobile", 85.45M); p.Show(); }