如何在公共方法中调用私有构造函数?我想从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 –
这正是我想要的,谢谢乔恩!对不起,缺少咖啡。 –