【发布时间】:2016-05-14 04:12:37
【问题描述】:
【问题讨论】:
-
您是否删除了任何文本框或按钮?因为我以前也遇到过这种情况。您所要做的就是查看表单设计中的代码并添加
//将其注释掉。 -
我没有删除任何东西。编码是正确的。但仅在形式上发生这种类型的错误。
标签: .net
【问题讨论】:
// 将其注释掉。
标签: .net
这意味着您的代码使用了一个设置为 null 的对象引用变量(即它没有引用实际的对象实例)。
为防止该错误,可能为 null 的对象应在使用前进行 null 测试。
if (myvar != null)
{
// Go ahead and use myvar
myvar.property = ...
}
else
{
// Whoops! myvar is null and cannot be used without first
// assigning it to an instance reference
// Attempting to use myvar here will result in NullReferenceException
}
从其他帖子复制,但很好的解释。
【讨论】: