I have a Mainclass in my code with various a list and various subset. When I try
main k = new main();
k.main.addressinfo.addressline1 = "XXX";
I am getting the error "Object reference not set to an instance of an object// NULLEXCEPTION."
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; }
}
Since the Class contains lists and arrays I am a little confused as to how to set the default values of string to EMPTY but not NULL. Also How do I ensure that the Childrens by default have One EMPTY but not NULL Object?