【发布时间】:2020-02-28 09:32:48
【问题描述】:
private static readonly SmtpClient SmtpClient = new SmtpClient (...)
public Constructor()
{
SmtpClient.SendCompleted += new SendCompletedEventHandler(SendCompletedMethod);
// Above is allowed and legal. Why, when the field is marked as static read-only?
}
任何想法为什么允许这样做?我真的很困惑。此外,如果构造函数执行了两次,这将产生错误。
【问题讨论】:
-
是引用类型
-
您并没有更改
SmtpClient引用 - 您只是更改其中一个字段。
标签: c# .net-core constructor static smtpclient