I am trying to create chained constructors but well, im no good at it and need some help!
I get an message in one of the constructor telling me there are no constructors that takes two arguments. ?
What does it mean by that? I need it to handle 3 strings sent from another class and that leads me into the second question and that is i cant call this from my other class…i have tried everything and i just cant get it to do it 🙁 I feel there is something big i am missing about constructors but i am sure that someone can point me in the right way!! Please i can use any and all help here!!! I have read my C# books on this subject and they arent much help and i have googles and well there are many examples but none really makes much sense to me as i thought my code would work.
Here is my class i have the constructors i need to send variables to.
public class Phone
{
//Private Phone
private string m_persPhone;
//Other Phone
private string m_otherPhone;
//Work Phone
private string m_privatePhone;
public Phone()
{
}
public Phone(string personalPhone)
: this(personalPhone, string.Empty) //<---Problem is HERE...
{
}
public Phone(string personalPhone, string otherPhone, string privatePhone)
{
m_persPhone = personalPhone;
m_otherPhone = otherPhone;
m_privatePhone = privatePhone;
}
public string personalPhone
{
//Personal Phone
get { return m_persPhone; }
set { m_persPhone = value; }
}
public string otherPhone
{
//Other Phone
get { return m_otherPhone; }
set { m_otherPhone = value; }
}
public string privatePhone
{
//Private Phone
get { return m_privatePhone; }
set { m_privatePhone = value; }
}
public string GetToStringItemsHeadings
{
get { return string.Format("{0,-20} {1, -20} {2, -20}", "Personal Phone", "Other Phone", "Private Phone"); }
}
public override string ToString()
{
string strOutPhone = string.Format("{0,-20} {1, -20} {2, -20}", m_persPhone, m_otherPhone, m_privatePhone);
return strOutPhone;
}
}
}
//Regards
This code:
is looking for a constructor that takes two string arguments.
The portion of the code
means “Look for a constructor for this same class that takes the two arguments in my argument list (in this case, two strings) and then invoke that constructor”.
However, you don’t define one. You could use the one that takes three string argument instead like this: