当前位置: 代码迷 >> ASP.NET >> 这是咋回事
  详细解决方案

这是咋回事

热度:2069   发布时间:2013-02-25 00:00:00.0
这是怎么回事
C# code
List<Dept>[] GetDeptList = null;List<Dept> aaa = new PublicLibraryBLL().GetContainDept(CInfo);GetDeptList[0] = aaa;


运行提示
System.NullReferenceException: 未将对象引用设置到对象的实例。
行 55: GetDeptList[0] = aaa;

有空帮忙指点一下,
须要什么我提供

------解决方案--------------------------------------------------------
List<Dept>[] GetDeptList = null;只是声明了GetDeptList ,没有添加任何数据,你访问[0]索引当然不存在了

------解决方案--------------------------------------------------------
想赋值,也要先添加啊,GetDeptList.Add
------解决方案--------------------------------------------------------
虽然不是很明白你为什么这样写?
数组是要在new 时定义长度的
C# code
string[] aaa=new string[]{"1","2","3"};//3个GetDeptList =new List<Dept>[] {aaa}
------解决方案--------------------------------------------------------
探讨

List<Dept>[] GetDeptList = null;只是声明了GetDeptList ,没有添加任何数据,你访问[0]索引当然不存在了

------解决方案--------------------------------------------------------
楼主仔细检查一下呀
------解决方案--------------------------------------------------------
参数为空或者没设置
------解决方案--------------------------------------------------------
PublicLibraryBLL().GetContainDept(CInfo);这个得到的类型是什么?
  相关解决方案