我正在使用MVP模式构建应用程序.为了在演示者中发生事情,我在视图中创建事件,演示者将观察它们.ReSharper给我一个关于可能的空引用异常的警告,我看到在触发事件之前检查null的教程.事件究竟能以何种方式为空?以下是我的代码示例:
public partial class PrinterSelectView : Form, IPrinterSelectView
{
public PrinterSelectView()
{
InitializeComponent();
}
public event Action Canceled;
public event Action Saved;
private void btnCancelClick(object sender, EventArgs e)
{
if(Canceled != null)
{
Canceled();
}
}
}
Run Code Online (Sandbox Code Playgroud)