本文介绍了如何修复数组错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个字符串数组:

Hi,
I have have a string array:

public class Example
{
    public string[] Layers = new string[] { };

    public Example()
    {
        //Just to be safe...
        this.Layers = new string[] { };
    }
}



每当我尝试访问该字符串数组的成员时:


and whenever I try to access a member of that string array:

Example test = new Example();
test.Layers[Convert.ToInt32(numericUpDown1.Value)] = textbox1.Text;

它总是给我一个IndexOutOfRange异常。为什么会发生这种情况,我该如何解决?因为从逻辑上讲它应该有用吗?..也有人可以在阵列开始的地方回答吗?它是1还是0?



谢谢Jake

it always gives me an IndexOutOfRange exception. Why is this happening and how can I fix it? Because logically it should work?.. and also can someone please answer at where an array starts? Is it 1 or 0?

Thanks Jake

推荐答案

public class Example
   {
       public string[] Layers = new string[7] ;

       public Example()
       {
           //Just to be safe...
           this.Layers = new string[7] ;
       }
   }



Morevover数组索引从C开始0#



看看这个



[]


this.Layers = new string[] { "a", "b", "c" };


这篇关于如何修复数组错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 03:53