相关疑难解决方法(0)

-event-只能出现在+ =或 - =的左侧

我在一个循环中有一个事件.我试图阻止将同一方法多次添加到事件中.我已经实现了addremove访问器.

但是,我收到一条错误消息:

ItemsProcessed can only appear on the left hand side of += or -=

当我试着打电话给他们时,即使是在同一个班级里.

ItemsProcessed(this, new EventArgs()); // Produces error

public event EventHandler ItemsProcessed
{
    add
    {
        ItemsProcessed -= value;
        ItemsProcessed += value;
    }
    remove
    {
        ItemsProcessed -= value;
    }
}
Run Code Online (Sandbox Code Playgroud)

c# event-handling

31
推荐指数
3
解决办法
4万
查看次数

标签 统计

c# ×1

event-handling ×1