怎么把我输入的信息 在最后全部显示出来
class program
{
static void Main(string[] args)
{
Commodities[] c = new Commodities[3];
for (int i = 0; i < 3; i++)
{
Console.WriteLine("添加第{0}件商品:\n请输入商品编号:",i+1);
c[i]=new Commodities();
c[i].id = int.Parse(Console.ReadLine());
Console.WriteLine("请输入商品名:");
c[i].name = Console.ReadLine();
Console.WriteLine("请输入单价:");
c[i].price = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("添加成功.");
}
}
}
class Commodities
{
public int id;
public string name;
public double price;
}
比如说这样
所有商品如下:
编号 商品名 价格
1 玉米 3.0
2
------解决方案--------------------
Console.WriteLine("{0}\t{1}\t{2}", "编号", "商品名", "价格");
foreach (var item in c)
{
Console.WriteLine("{0}\t{1}\t{2}", item.id, item.name, item.price);
}