我有一个静态类,看起来像这样:的NullReferenceException静态类属性
namespace Argus
{
static class Argus
{
public static List<Branch> myArgus;
}
}
和其他地方在我的代码我有这样的:
// Add this branch to myArgus
Argus.myArgus.Add(branch);
当我运行代码,我得到这个错误:
Object reference not set to an instance of an object.
我已经验证branch
是有效的(它是Branch
的对象类),并不知道这里可能是错误的。我试图从文本文件中读取分支数据。
为什么'myArgus'永远是非空的?另外:不要这样做。像这样的静态状态几乎总是真的很糟糕(无论是在隔离性和线程安全性方面) – 2012-03-26 19:42:12