如何在公共方法中調用私有構造函數?我想從setter和setter調用對象初始值設定項來公開調用。調用嵌套的私有構造函數
private MyMailer() // objects initializer
{
client = new SmtpClient(SMTPServer);
message = new MailMessage {IsBodyHtml = true};
}
private MyMailer(string from) //from setter
{
SetFrom(from);
}
public MyMailer(string from, string to, string cc, string bcc, string subject, string content)
{
foreach (string chunk in to.Split(new string[] {";"}, StringSplitOptions.RemoveEmptyEntries))
{
AddTo(chunk);
}
foreach (string chunk in cc.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries))
{
AddCC(chunk);
}
foreach (string chunk in bcc.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries))
{
AddBCC(chunk);
}
SetSubject(subject);
SetMessage(content);
Send();
}
你的第二句話對我來說完全不清楚。如果你在一起討論鏈接構造函數,請參閱http://stackoverflow.com/questions/985280/can-i-call-a-overloaded-constructor-from-another-constructor-of-the-same-class-i ?rq = 1 –
這正是我想要的,謝謝喬恩!對不起,缺少咖啡。 –