我有mainclass
各种子类的 aa。
public class Mainclass
{
public List<main> mainset { get; set; }
// do sth to load and save model info
}
public class main
{
public personalinfo info { get; set; }
public addressinfo currentaddr { get; set; }
public addressinfo[] otheraddr { get; set; }
public telephone currenttel { get; set; }
public telephone[] othertel { get; set; }
}
public class addressinfo
{
public string Addressline1 { get; set; }
public string Addressline2 { get; set; }
public string City { get; set; }
public string postcode { get; set;
}
public class telephone
{
public int tel { get; set; }
}
如何检查孩子是否已初始化?我尝试了以下方法,但即使我尝试检查!Null,我也会收到 Null 异常。
if (main.currentaddr != null)
{
addressinfo add = new addressinfo();
//do sth
}