【发布时间】:2015-03-28 12:20:11
【问题描述】:
我创建了一个名为 product 的类,并在我的主程序中向我的类添加了不同的产品,如下所示:
product1 = new Product();
product1.Name = "product1";
product1.Price = 3.50;
Product product2 = new Product();
product2.Name = "product2";
product2.Price = 4;
我有一个列表框,我用这种方法填充:
private void fillProducts(string item)
{
lstProducts.Items.Add(item);
}
所以当我使用该方法时,它看起来像这样:fillProducts(product1.Name);
现在我想要实现的是,当我按下按钮 (btnConfirm) 时,它会看到在列表框中选择了哪个产品,并获取产品的价格并将其显示在标签中
lblConfirm.Text = "The price of product1 is: " + *the price of product1*;
所以我需要在标签中显示 product1 的价格,并且我不想为每个产品都使用 if 语句,因为会有超过 200 个 if 语句。如果这个问题有什么不清楚的地方,请告诉我。
【问题讨论】: