What does the end of the header mean?
MobilePhone(string phoneNumber, string name) : this(phoneNumber)
{
this.name = name;
}
What does the end of the header mean?
MobilePhone(string phoneNumber, string name) : this(phoneNumber)
{
this.name = name;
}
: this(phoneNumber)
invokes another constructor overload that only accepts a phone number (or at least a string
):
MobilePhone(string phoneNumber, string name) : this(phoneNumber)
{
this.name = name;
}
//this one is invoked using 'this(phoneNumber)' above
MobilePhone(string phoneNumber)
{
this.phoneNumber = name;
}
I guess you are referring to the : this(phoneNumber)
.
This is basically a second constructor call. It is called constructor chaining.
You basically have two constructors and one calls the second one for its contents.
//Constructor A gets called and calls constructor B
MobilePhone(string number, string name) : this(number)
{
this.name = name;
}
//This would be constructor B
MobilePhone(string number)
{
this.number = number;
}
this(phoneNumber)
means 'before you call the below code, call the other MobilePhone
constructor (which takes a single string
parameter), passing in phoneNumber
as the parameter to it'.