Members are not implicitly constructed. They're initialized with their default values (i.e. null
for reference type members), which is why your child1
member is null.
You need to create an instance of child1
:
public Parent
{
child1 = new Child();
}
On a sidenote, I think you are being confused by constructor call rules for inherited classes. If your Child
class inherited your Parent
class, the Parent
class' default (i.e. parameterless) constructor would be implicitly called (if it existed):
class Parent
{
protected string member;
public Parent()
{
member = "foo";
}
}
class Child : Parent
{
public Child()
{
// member is foo here; Parent() is implicitly called
}
}