问题描述
可能重复:结果
的
例如, System.NullReferenceException
是未处理,与消息对象引用不设置到对象的实例。
For example, "System.NullReferenceException
was unhandled", with Message "Object reference not set to an instance of an object."
这是什么异常的含义,以及它如何解决?
What is the meaning of this exception, and how can it be solved?
推荐答案
这意味着你已经试过访问的一些成员是不是有:
It means you've tried to access a member of something that isn't there:
string s = null;
int i = s.Length; // boom
刚刚修复为空的东西。要么让非空,或先执行零测试。
Just fix the thing that is null. Either make it non-null, or perform a null-test first.
还有一个的的位置有关可空< T>
,泛型和新
通用约束 - (!不过,赫克说,我打了这个问题)。有点不太可能,虽然
There is also a corner-case here related to Nullable<T>
, generics and the new
generic constraint - a bit unlikely though (but heck, I hit this issue!).
这篇关于什么是的NullReferenceException的含义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!