Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 遍历foreach循环以查找值_C#_List_Foreach - Fatal编程技术网

C# 遍历foreach循环以查找值

C# 遍历foreach循环以查找值,c#,list,foreach,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 //OrderL

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

//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


我是新来的,所以我真的需要帮助。谢谢

从您的代码中,不太清楚您为什么要按比萨饼顺序传递而不使用它。 也许您应该将其添加到orderlist中,然后检查方法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
}

在方法中放置断点并检查
OrderList
。该变量来自何处,以及参数
PizzaOrder
与该方法有何关系?要回答此问题,您(或任何其他人)需要了解以下内容:什么是
dailyRevenue
,它是如何声明的?
GetAmountDue
的代码是什么?什么是
OrderList
,它是如何声明的,调用该方法时列表的内容是什么?如果你能识别出这些东西并亲自浏览代码,你可能会找到答案。“做一个搜索。寻找免费的比萨饼。然后看看它是否在这个驱动器中出现。”欢迎来到SO。我看到你今天问了3个关于比萨饼的问题。。。。。你应该在其他问题中至少将正确答案标记为已回答。您应该显示getAmountDue函数,以便我们可以看到错误。祝你的家庭作业好运。我解决了我的问题!这对我来说是一个愚蠢的逻辑错误。lol。我忘了从我的点击事件将我的PizzaOrder对象(order)传递到我的列表。谢谢你的建议!