I'm setting up a console application that will take the input from the user and make a new object with my class "Items". But I want a loop there as well so the user can do multiple inputs, what kind of loop should I use and how does it works if I want the variable "foo" to change through the loop?
I've tried some for loops and I'm trying to put the "i" after "foo" but did't get it to work...
Console.WriteLine("Write a item:");
string item = Console.ReadLine();
Console.WriteLine("Write a price:");
decimal price = Convert.ToDecimal(Console.ReadLine());
var foo = new Items(item, price);
Console.Write(" {0} {1} ", foo.Item, foo.Price);
Edit: Sorry, I was thinking I should simplify everything. My mistake! Like one of the comment said, I want to store every object created at each iteration. Then showing it like a "shopping list" with the most expensive at the top and the cheapest item at the bottom.
This is one of the things I've tried. (not a for loop but with the same concept of i++ and so on)
do
{
Console.WriteLine("Insert items that you want to buy, when you are finnish, write 'done'");
Console.Write("Insert a item: ");
string item = Console.ReadLine();
switch (item.ToLower())
{
case "done":
break;
default:
Console.WriteLine("Write a price:");
decimal price = Convert.ToDecimal(Console.ReadLine());
var foo(i) = new Items(item, price);
Console.Write(" {0} {1} ", foo.Item, foo.Price);
break;
}
i++;
} while (item != "done");
//Then show the list in order