通过foreach循环迭代寻找值

时间:2014-03-06 13:45:09

标签: c# list foreach

我正在使用列表对象并尝试迭代它以获得当天的总销售额。迭代对象,然后添加总销售额。

//create a method to get daily revenue
public void GetDailyRevenue(PizzaOrder order)  
{
  //for each increments the total daily revenue (sale)
  //then increments the total revenue for each order
  //OrderList always have pizzaorder objects stored var only messing up here
  foreach (PizzaOrder po in OrderList)
  {
     dailyRevenue += order.GetAmountDue(po.NumberOfPizzas, po.NumberOfCokes);
  }
   //check what is the value of dailyRevenue here
}

我需要使用哪些代码来检查每日收入的价值?它没有遍历循环。当我输出时,它表示每日总收入为0.

我很新,所以我真的需要帮助。谢谢!

1 个答案:

答案 0 :(得分:0)

从你的代码中不清楚为什么你传递一个吃零食而不使用它。 也许您应该将它添加到订单列表中,然后检查您的方法getamountdue是否正常工作

例如:

//create a method to get daily revenue
public void GetDailyRevenue(PizzaOrder order)  
{
  //for each increments the total daily revenue (sale)
  //then increments the total revenue for each order
  //OrderList always have pizzaorder objects stored var only messing up here
  OrderList.Add(order);
  foreach (PizzaOrder po in OrderList)
  {
     dailyRevenue += order.GetAmountDue(po.NumberOfPizzas, po.NumberOfCokes);
  }
   //check what is the value of dailyRevenue here
}