问题
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();
来源:https://stackoverflow.com/questions/20945303/index-was-outside-the-bounds-of-the-array-c-sharp