尝试调用我的ToString()方法时,我收到上述错误消息。我不确定问题是什么。这是我的代码:
public override string ToString()
{
return string.Format("{0} Pizzas @ {1:C}: {2:C}\n" +
"{3} Cokes @ {4:C} {5:C}\n" +
"Order Amount: {6:C}\n" +
"Sales Tax: {7:C}\n" +
"Amount Due: {8:C}\n" +
"Amount Paid: {9:C}\n" +
"Change Due: {10:C}", numberOfPizzas, PIZZA_PRICE +
totalCostOfPizza, numberOfCokes, COKE_PRICE, totalCostOfCoke +
foodAndDrinkTotal, totalSalesTax, totalAmountDue, amountPaid, +
changeDue);
}
答案 0 :(得分:6)
您正在以字符串格式引用更多参数,然后提供。
通过它的外观,删除所有的加号(在参数列表中不是字符串连接)并插入逗号
答案 1 :(得分:2)
看起来你正在添加你不想要的东西?
试试这个:
public override string ToString()
{
return string.Format("{0} Pizzas @ {1:C}: {2:C}\n" +
"{3} Cokes @ {4:C} {5:C}\n" +
"Order Amount: {6:C}\n" +
"Sales Tax: {7:C}\n" +
"Amount Due: {8:C}\n" +
"Amount Paid: {9:C}\n" +
"Change Due: {10:C}", numberOfPizzas, PIZZA_PRICE,
totalCostOfPizza, numberOfCokes, COKE_PRICE, totalCostOfCoke,
foodAndDrinkTotal, totalSalesTax, totalAmountDue, amountPaid,
changeDue);
}