private void Form1_Load(object sender, EventArgs e)
        {
            A[] pp = new A[5];
            pp[2].L.Add(8);//错误:未将对象引用设置到对象的实例。
        
        }
        public struct A
        {
            public List<int> L;
        }

解决方案 »

  1.   

    A[] pp = new A[5]; 
    你这句仅仅是定义一个A类的数组,该数组并未初始化,只有是值类型的数组才会自动初始化
    引用类型的初始值都是null
    你得先分别
    pp[0]=new A();
    pp[1]=new A();
    ....
    或者
    A[] pp = new A[]{new A(),new A(),new A(),new A(),new A()};
      

  2.   

    你想干嘛?L.Add(pp[2]);//添加??
      

  3.   

    将结构中的定义改为public List <int> L = new List<int>(); 就OK了 因为你结构中的List集合没有初始化!!!!!!!
      

  4.   

    public struct A
            {
                public List <int> L;
            } 
    好象L也没有初始化,换成
           public struct A
            {
                public List <int> L=new List<int>();
            } 
      

  5.   


            public struct A
            {
                private List<int> _L;            public List<int> L
                {
                    get
                    {
                        if ( _L == null )
                        {
                            _L = new List<int>();
                        }                    return _L;
                    }
                    set
                    {
                        _L = value;
                    }
                }
            } 
      

  6.   

    public Class A 
            { 
                public List <int> L=new List<int>(); 
            } 
      

  7.   

    那就将结构换成一个类!!然后给类封装属性!!!!
    就是 Public List <int> L=new List<int>(){get;set;}; 
      

  8.   

    或者在Load事件中写
    pp[2].L = new List<int>();
    然后在PP[2].L.add(8);就OK了 
    总之一定要初始化List<int>就好了 !!!!!!!!!!!!
      

  9.   

    public struct A
            {
                public List <int> L;
    public A()
    {
    L=new List<int>();
    }
            }