D
DeveloperX
In an attempt to solve a problem further down I suggested the problem
might be caused by a missing constructor. Now, this led me to the
conclusion that I don't fully understand constructors, or have made
lots of assumptions.
Things I (think) know, please correct as necessary:
Constructors are called on instantiation.
Static constructors are called the first time a class is referenced.
There can be many constructors and you can chain them together with :
this()
Using : base() will call the base class's constructor.
If there isn't a constructor the constructor of the class's base will
be called. This will carry on up the chain until it hits object if no
constructors are found.
If the base class only has a parameterized constructor you need to
call it from your derived class as : base(required param)
The constructor of the base class is always called before the derived
class's constructor.
So why do I see every where:
public class Test
{
public Test()
{
//do nothing
}
//class stuff
}
what is the point of a public constructor that does nothing? I do it
all the time without ever thinking about it, and it seems I'm not
alone. I could understand if it was protected or private, but public?
might be caused by a missing constructor. Now, this led me to the
conclusion that I don't fully understand constructors, or have made
lots of assumptions.
Things I (think) know, please correct as necessary:
Constructors are called on instantiation.
Static constructors are called the first time a class is referenced.
There can be many constructors and you can chain them together with :
this()
Using : base() will call the base class's constructor.
If there isn't a constructor the constructor of the class's base will
be called. This will carry on up the chain until it hits object if no
constructors are found.
If the base class only has a parameterized constructor you need to
call it from your derived class as : base(required param)
The constructor of the base class is always called before the derived
class's constructor.
So why do I see every where:
public class Test
{
public Test()
{
//do nothing
}
//class stuff
}
what is the point of a public constructor that does nothing? I do it
all the time without ever thinking about it, and it seems I'm not
alone. I could understand if it was protected or private, but public?