-6

What does the end of the header mean?

MobilePhone(string phoneNumber, string name) : this(phoneNumber)
{
    this.name = name;
}
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

3 Answers3

1

: 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;
}
mm8
  • 163,881
  • 10
  • 57
  • 88
0

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;
}
Max Play
  • 3,717
  • 1
  • 22
  • 39
0
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'.

mjwills
  • 23,389
  • 6
  • 40
  • 63