Exception while using String.Format “Index (zero based) must be greater than or equal to zero and less than the size of the argument list.”

瘦欲@ 提交于 2019-12-07 16:24:29

For reference, here is my working code too:

string[] array = new string[] { "a", "b", "c", "d" };

string refFormat = "{2} {0}";

string newStr = String.Format(refFormat, array);

Console.WriteLine(newStr);

I did not encounter an error when running the above code.

You are not giving the parameters correctly , it needs to be indexed as {0} {1} and so ons

String.Format(refFormat,array[2],array[0]);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!