-6

What does the end of the header mean?

MobilePhone(string phoneNumber, string name) : this(phoneNumber)
{
    this.name = name;
}
marc_s
  • 704,970
  • 168
  • 1,303
  • 1,425

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
  • 150,971
  • 10
  • 50
  • 74
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
  • 2,797
  • 23
  • 34
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
  • 22,686
  • 6
  • 37
  • 60