索引(从零开始)必须大于或等于零且小于参数列表的大小

Pro*_*bie 0 c#

尝试调用我的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);
}        
Run Code Online (Sandbox Code Playgroud)

Chr*_*nty 6

您正在提供的字符串格式中引用更多参数.

通过它的外观,删除所有的加号(在参数列表中不是字符串连接)并插入逗号

  • 除了那些加入格式字符串*的元素之外,删除所有的`+`s,*. (2认同)