Index was outside the bounds of the array c#

匿名 (未验证) 提交于 2019-12-03 02:38:01

问题:

I have an array with size[5]. I added 5 values into this array and then removed the values. Now my array have only one value. If I add another value to this array it shows the error Index was outside the bounds of the array.

回答1:

If you have an array of size 5 you can add values 0 to 4 (arrays start at index 0):

object[] arr = new object[5]; arr[0] = new object(); arr[4] = new object();  // this will give your Index was outside the bounds of the array exception: arr[5] = new object();


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