日期:2014-05-19  浏览次数:20932 次

如何判断数组某个元素是否为空。 200分求解!
如何判断数组某个元素是否为空。
role[5,12];//数组role  
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()


------解决方案--------------------
if (role[a,b] != null && !role[a, b].ToString().Trim().IsEmpty())//