0

The following line gives an error:

 Console.WriteLine("Order:{0},\n Placed:{1},\nshipped:{2},\nTo address:{3} ,{4}, {5}\n\n" + orderid, orderdate, shipdate, shipname, shipaddr, shipcity);

It shows an error as:

(Index (zero based) must be greater than or equal to zero an d less than the size of the argument list.)

Help me out to resolve this error. I know this error happened because of the place holder provided are greater than the variables provided.

4

4 回答 4

4

我猜你想要:

Console.WriteLine("Order:{0},\n Placed:{1},\nshipped:{2},\nTo address:{3} ,{4}, {5}\n\n", orderid, orderdate, shipdate, shipname, shipaddr, shipcity);

请注意 + 不存在。

于 2013-01-25T07:20:23.017 回答
3
Console.WriteLine("Order:{0},\n Placed:{1},\nshipped:{2},\nTo address:{3} ,{4}, {5}\n\n",orderid, orderdate, shipdate, shipname, shipaddr, shipcity);

应该解决问题。

于 2013-01-25T07:20:08.240 回答
1

在你的第一个论点之前你有 a+而不是 a 。,更正:

Console.WriteLine("Order:{0},\n Placed:{1},\nshipped:{2},\nTo address:{3} ,{4}, {5}\n\n", orderid, orderdate, shipdate, shipname, shipaddr, shipcity);

因此,该方法仅识别 5 个参数,而不是 6 个。

于 2013-01-25T07:21:16.287 回答
1

为什么格式字符串的末尾有一个加号?当格式字符串需要 6 时,这会导致参数为 5。

更改如下:

Console.WriteLine("Order:{0},\n Placed:{1},\nshipped:{2},\nTo address:{3} ,{4}, {5}\n\n", orderid, orderdate, shipdate, shipname, shipaddr, shipcity);
于 2013-01-25T07:22:17.937 回答