I have a class like this,
public class person
{
name Name {set; get;}
string Address {set; get;}
}
public class name
{
string First {set; get;}
string Last {set; get;}
}
Now when I create the object an try to set the first or last name I get an error. “Object reference not set to an instance of an object.”
person Person = new person();
Person.Name.First = "John";
Person.Name.Last ="Smith";
What am I doing wrong?
You need to initialise the name class instance too
You could also do this in the constructor of
personif you wishOr even try