有如下语句,本意是想如果strArray4数组的值不等于"无说明",就将它的值依次合并然后赋值给BZDemo数组:
string[] BZDemo = null;
for (int j = 0; j < table.Rows.Count; j++)
{  
   strArray4 = table.Rows[j]["los"].Split(base.sDefaultSplit.ToCharArray());
for (int x = 0; x < 5; x++)
{
   String tempbz=strArray4[x];
  if (tempbz != "无说明")
  {
     BZDemo[x] = BZDemo[x].ToString() + tempbz;
   }
  else
  {
     BZDemo[x] = BZDemo[x];
  }
}
}但运行时显示”未将对象引用设置到对象的实例“,
将BZDemo[x] = BZDemo[x].ToString() + tempbz;
BZDemo[x] = BZDemo[x];
这两句屏蔽后可正常运行,请问这两句有什么问题吗?该如何解决呀?多谢了

解决方案 »

  1.   

    string[] BZDemo = null;
    你声明后没有实例化啊
      

  2.   

    没有给BZDemo开辟空间。
    new一下就好了
      

  3.   

    不清楚(int x = 0; x < 5; x++)中的你的x怎么保证不大于 strArray4[]数组大小如是未确定的数组大小建议用List<string>,然后再转换为string[]可改这样:string[] BZDemo = new string[5] ;
      

  4.   

    string[] BZDemo = null;請實例化該對象。