我想按顺序减去BillCost2016和BillCost2015之间的差异,并将结果保存在第三个列表中。此外,有没有办法将我的代码与月份和成本对齐的位置对齐。我是编码的新手,非常感谢任何帮助。这是我的代码:
List<int> BillCost2016 = new List<int>();
BillCost2016.Add(120);
BillCost2016.Add(220);
BillCost2016.Add(250);
BillCost2016.Add(180);
BillCost2016.Add(150);
BillCost2016.Add(260);
List<int> BillCost2015 = new List<int>();
BillCost2015.Add(150);
BillCost2015.Add(210);
BillCost2015.Add(230);
BillCost2015.Add(180);
BillCost2015.Add(160);
BillCost2015.Add(280);
List<string> BillMonth2016 = new List<string>();
BillMonth2016.Add("Jan");
BillMonth2016.Add("Feb");
BillMonth2016.Add("Mar");
BillMonth2016.Add("Apr");
BillMonth2016.Add("May");
BillMonth2016.Add("June");
CombinedList(BillMonth2016, BillCost2016);
CombinedList(BillMonth2016, BillCost2015);
DisplayAverage2016(BillCost2016);
DisplayAverage2015(BillCost2015);
Console.ReadKey();
}//end main
public static void CombinedList (List<string>Howdy, List<int>Cookie)
{
foreach (var cookie in Howdy)
{
Console.WriteLine(cookie);
}
foreach (var candy in Cookie)
{
Console.WriteLine(candy);
}
}
public static void DisplayAverage2016 (List<int> Howdy)
{
Console.WriteLine("The Average for 2016 is: " + Howdy.Average());
}
public static void DisplayAverage2015 (List<int>Howdy)
{
Console.WriteLine("The average for 2015 is: " + Howdy.Average());
}
}
}