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

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

在coding 时,遇到了以上错误信息,
检查了代码,在这里插入图片描述不出来问题
经调试后发现是以下写法导致,

// 经常用到string.format
var ret = string.Format("{0}{1}{2}{3}", "test", "test1", "test2");

定义4个变量,实际赋值3个
该写法在编译时不报错,但是运行时会抛出如题异常
coding 要规范,谨防入坑

你可能感兴趣的:(C#,.net)