If a method is created like below, what is the result of ":this()" at the end? why can it be needed?
public Product(int new_id, short product_name, string product_type) : this()
Thanks
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Mar 26, 2013, 8:55 AM
The Product class contains (at least) two constructors. One takes three arguments (an int, short and a string) and the other takes no arguments.
When the constructor which takes 3 arguments is invoked, the first thing it does is to call the constructor which takes no arguments - this is what :this() does.
The body of the constructor then executes normally.
Constructor chaining therefore avoids having to duplicate code.