a[10]
比如数组长度是10,但是数组前8个有数据,后面2个没有赋值。 那如何进行判断是否为空呢?

解决方案 »

  1.   

    只能一个一个判断,如果是对象数组就判断是否为null我觉得你应该用List模版类来处理更合适。
      

  2.   

    用哪个语句 is “” ,is null,.Equals("") 都判断不出
      

  3.   

    c#好像直接有方法实现toarraylist吧?arraylist里面可以直接判断是否为空。
      

  4.   

    if( a[10] == null ) MessageBox.Show("空");
      

  5.   

    for (i=0;i<10;i++)
    {
    if (a[i]==null)
    {
    MessageBox.Show(a[i]+"为空!");
    }
    }
      

  6.   

    role[5,12];
    for (int a = 0; a < role.GetLength(0); a++)
    {
      for (int b = 0; b < role.GetLength(1); b++)
        {                    
            if (role[a, b].ToString().Trim() !=null)//错误提示:未处理NullReferenceException
                 {
                    LVItem.SubItems.Add(role[a, b].ToString());
                  }
         }
    }
    }未处理 System.NullReferenceException
      Message="NullReferenceException"
      StackTrace:
        位于 MobileTax.cls.img.PopulateListView()
        位于 MobileTax.ermenu.ermenu_Load()
        位于 System.Windows.Forms.Form.OnLoad()
        位于 System.Windows.Forms.Form._SetVisibleNotify()
        位于 System.Windows.Forms.Control.set_Visible()
        位于 System.Windows.Forms.Control.Show()
        位于 MobileTax.cls.img.ListView1_ItemActivate()
        位于 System.Windows.Forms.ListView.OnItemActivate()
        位于 System.Windows.Forms.ListView.HandleItemActivate()
        位于 System.Windows.Forms.ListView.WnProc()
        位于 System.Windows.Forms.Control._InternalWnProc()
        位于 Microsoft.AGL.Forms.EVL.EnterModalDialog()
        位于 System.Windows.Forms.Form.ShowDialog()
        位于 MobileTax.Form1.timer1_Tick()
        位于 System.Windows.Forms.Timer._WnProc()
        位于 System.Windows.Forms.ApplicationThreadContext._InternalContextMessages()
        位于 Microsoft.AGL.Forms.EVL.EnterMainLoop()
        位于 System.Windows.Forms.Application.Run()
        位于 MobileTax.Program.Main()
      

  7.   

    问题解决 方法如下: if (role[a, b] != null) // ToString() 是 Object 的方法,而 null 不是 Object