首先设置一个类:
public class tmpclass
{ int app;
  public tmpclass()//构造函数
  {   }
  public int iapple//属性
 {get    {return app;}
  set {app=value;}

 }
}
然后:
   class Class1
     {static tmpclass [][] tmp;
         static void Main(string[] args)
{
tmp = new tmpclass[3][];
tmp[0] = new tmpclass[5];
tmp[1] = new tmpclass[4];
tmp[2] = new tmpclass[2];

tmp[0][0].iapple=0;//*******************
            
Console.WriteLine("a={0}",tmp[0][0]);
}
}
}之后总是出现对话框:未处理的“System.NullReferenceException”类型的异常出现在 ConsoleApplication1.exe 中。
其他信息: 未将对象引用设置到对象的实例。然后星号那行变黄,请帮忙指正一下,不胜感激。

解决方案 »

  1.   

    tmp[0] = new tmpclass[5];只是将tmp[0]声音为一个包含五个元素的数组,并没有对其中的五个元素进行实例化,如需要全实例化应写成:
    class Class1
    {
    static tmpclass [][] tmp;
    static void Main(string[] args)
    {
    tmp = new tmpclass[3][];
    tmp[0] = new tmpclass[5];
    tmp[1] = new tmpclass[4];
    tmp[2] = new tmpclass[2];

    for ( int i = 0, length = tmp[0].Length; i < length; i++ ) {
    tmp[0][i] = new tmpclass();
    } tmp[0][0].iapple=0;//*******************
                
    Console.WriteLine("a={0}",tmp[0][0]);
    }
    }