空异常未处理 [英] Null Exception is not handling

查看:78
本文介绍了空异常未处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行c#.Net应用程序时出现问题.在Visual Studio 2010 Ultimate中开发的应用程序.语言是C#.Net 2010和Framework 4.0.

I had a problem while running c#.Net application. Application developed in Visual Studio 2010 ultimate. Language is C#.Net 2010 and Framework 4.0.

在调试应用程序时,遇到空"的情况.值中的值,应用程序将退出.

While debugging the application, once it encountered a 'null'  value in the property, the application will exit.

例如:

公共班级员工

{

公共字符串名称

{

获取;

设置;

}

}

公开员工详细信息

{

获取;

设置;

}

 

如果details的值为null,则在访问Detials.Name时,它必须显示nulll异常.但是目前它没有显示任何空异常,应用程序将直接退出而不显示任何异常.请帮助我解决这个问题.

If the value of details is null then while accessing Detials.Name, it must shows nulll exception. But currently it si not showing any null exception the application will simply exit without showing any exception. Please help me to solve this.

推荐答案

如果尚未设置Setter,为什么还要允许代码访问Getter(获取访问器)?

why do you allow the code to access to the Getter (get accessor), if Setter was not yet set?

由于这个原因,get,set属性是正确的,首先,您必须对其进行设置,然后再获得预设值.

The get, set properties are meat right from this reason, 1st you have to set it, and then you get thepre-set value back.

您介意向我展示更多代码,在此处创建Employee类的新实例,以及如何尝试设置属性吗?

Would you mind showing me more code, there where you create a new instance of a class Employee, and how you are trying to Set the properites?


这篇关于空异常未处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆