I have written a console Application for POS(point of sale). It was my assignment. I completed it successfully but my professor asked to do it again with structure and list. Here is my code for just structure and list, i have omitted unnecessary code of application:
namespace simplePOS
{
struct Product
{
public string productName;
public double productUnitPrice;
public int productQty;
}
class Program
{
static void Main(string[] args)
{
List<Product> Products = new List<Product>();
Product P;
P.productName = Console.ReadLine();
P.productUnitPrice = Convert.ToDouble(Console.ReadLine());
P.productQty = Convert.ToInt32(Console.ReadLine());
Products.Add(P);
foreach(Product x in Products){ //This doesn't work.
Console.WriteLine(x);
}
Console.ReadLine();
}
}
Now as you can see i have created a struct and then created an list and saved object of struct "P" in list. Now my question is how can i access that object "P" saved in list to display several products in some loop, say for loop?