什么是NullReferenceException
试图访问或取消引用空对象引用时引发的异常。
继承链
-
ObjectExceptionSystemExceptionNullReferenceException
说明
尝试访问值为空的类型上的成员时,将引发NullReferenceException异常。NullReferenceException异常通常反映开发人员错误,可能引发的情况如下:
- 忘记了实例化引用类型
- 在初始化数组之前,忘记了维度。
- 从方法获取null返回值,然后对返回的类型调用方法。
- 因此,永远不会计算
null的测试。 - NullReferenceException 异常。
- NullReferenceException 异常。
NullReferenceException: callvirt、cpblk、cpobj、initblk、ldelem.<type>、ldelema、ldfld、ldflda、ldind.<type>、ldlen、stelem.<type>、stfld、stind.<type>、throw和 unbox。
HRESULT
NullReferenceException 使用值为0x80004003 的 HRESULT COR_E_NULLREFERENCE。