: base(...)
If you omit the call to the base constructor, it will automatically call the default base constructor.
It is mandatory to call the base constructor explicitly if there is no default constructor.
Even if there is a default constructor, you can still call a different constructor than the default constructor. In this case, you can still use base(foo, bar) to call a different constructor than the base constructor.
I do not consider it a bad practice to omit base() when you want to call the default constructor of the base class, although if you like to be explicit, I see no harm in including it. This is a matter of taste.
: this(...)
This syntax allows you to call one constructor with a different signature from another within the same class. This is never necessary, but can sometimes be useful.
An example of when this might be useful is the reuse of common code in constructors. For example, in C # 3.5 or before you want to model optional parameters for the constructor:
Foo(int x, int y) { this.x = x; this.y = y; } Foo(int x) : this(x, 10) {}
C # 4.0 advanced options are now available that reduce the need for this approach.
An alternative way to reuse code in constructors is to include it in a static function that is called from every constructor that wants to use it.
Mark Byers Sep 26 '10 at 11:20 2010-09-26 11:20
source share