事件类型不能是Action<&gt ;?

时间:2010-06-13 23:50:03

标签: c# .net events delegates

这是有效的

public event Func<int,int> createEvents;

但为什么不呢?

public event Action<int> createEvents;

1 个答案:

答案 0 :(得分:1)

public event Action<int> CreateEvents;

完全有效。也许您的事件处理方法与Action<T>代理不匹配。

也许你有这样的事情:

    public event Action<int> CreateEvents;
    public event Func<int, int> CreateEvents2;

    public int OnCreateEvents2(int value)
    {
        Func<int, int> handler = CreateEvents2;
        if (handler != null) return handler(value);

        return 0;
    }

    public void OnCreateEvents(int value)
    {
        Action<int> handler = CreateEvents;
        if (handler != null) handler(value);
    }