Lets say I have the following classes
class animal
{
public string name;
public animal(string name)
{
this.name = name;
}
}
and also
class dog : animal
{
public string breed;
public dog(string name, string breed): base(name)
{
this.breed = breed;
}
}
and finally
class poodle : dog
{
public poodle(string name, string breed, int hairLength): base(name, breed)
{
//in here, name is = null for some reason.
}
}
The issue is that when I have a three level hierarchy of inheritance, the base constructor (animal
) seems to get called after the poodle
constructor (name == null). But in the poodle
constructor, I may of wanted to access some of the properties that were set in the base constructor, etc.
Does anyone know how this can be done, or perhaps, a much better coding practice to resolving this issue? (Only solution I can think of is not really using constructors but rather have a separate initialize() method.
Thanks!