繁体   English   中英

索引超出数组C#的范围

[英]Index was outside the bounds of the array c#

我有一个size[5]的数组。 我在此数组中添加了5个值,然后删除了这些值。 现在我的数组只有一个值。 如果我向此数组添加另一个值,则表明错误Index was outside the bounds of the array

如果您有一个大小为5的数组,则可以将值0到4相加(数组从索引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();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM