Why is the base() constructor not necessary?
Posted
by Earlz
on Stack Overflow
See other posts from Stack Overflow
or by Earlz
Published on 2010-03-31T20:59:51Z
Indexed on
2010/03/31
21:03 UTC
Read the original article
Hit count: 330
c#
|constructor
Hello, I have a class structure like
abstract class Animal {
public Animal(){
//init stuff..
}
}
class Cat : Animal {
public Cat(bool is_keyboard) : base() //NOTE here
{
//other init stuff
}
}
Now then, look at the noted line. If you remove : base()
then it will compile without an error.
Why is this? Is there a way to disable this behavior?
I have had multiple bugs now from forgetting the base()
which I would have thought to be required on such a special thing as a constructor.
© Stack Overflow or respective owner