I would imagine this is quite a basic question in C#. I've got my head in a bit of spin with it though and I'm unsure of the correct way of sorting it.
I have a parent class with get/set properties and with a child class. When an instance of the class is created using new the property to the parent class is accessible but the child class isn't. I remember in C programming you have to create the memory space for this but I'm unsure of the correct way of doing this in C#.
Parent Class
class Parent_class
{
private int number;
public int Number
{
get { return number; }
set { number = value; }
}
private Child_class childclass;// = new Child_class();
public Child_class Childclass
{
get { return childclass; }
set { childclass = value; }
}
}
Child Class
class Child_class
{
private int number;
public int Number
{
get { return number; }
set { number = value; }
}
}
Main
static void Main(string[] args)
{
Parent_class test = new Parent_class();
test.Number = 3; //<--Ok
test.Childclass.Number = 4; //<--NullReferenceException
}