本文介绍了访问嵌套类时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好。代码是:
hi all. the code is:
public class PersonelInfoAndEmploymentInfo
{
public employmentInfo _empinfo{set;get;}
public PersonelInfo _pinfo { set; get; }
}
public class PersonelInfo
{
//some fields
}
public class employmentInfo
{
//some fields
}
//access from a winform
PersonelInfoAndEmploymentInfo person = new PersonelInfoAndEmploymentInfo();
person._empinfo.jobLocation = "asdasd";
//error:Object reference not set to an instance of an object.
推荐答案
public class PersonelInfoAndEmploymentInfo
{
public employmentInfo _empinfo{set;get;}
public PersonelInfo _pinfo { set; get; }
public PersonelInfoAndEmploymentInfo()
{
_empinfo = new employmentInfo();
_pinfo = new PersonelInfo();
}
}
像这样改变你的班级
change your class like this
这篇关于访问嵌套类时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!