Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在C中编写自定义事件处理程序加法器方法#_C#_Event Handling - Fatal编程技术网

C# 如何在C中编写自定义事件处理程序加法器方法#

C# 如何在C中编写自定义事件处理程序加法器方法#,c#,event-handling,C#,Event Handling,我已经定义了一个Foo类,并在Bar类中使用它,带有一个事件处理程序: public class Bar { public Bar() { Foo foo = new Foo(); foo.my_custom_event += my_event_handler; } public void my_event_handler() { // do work here } } 这是完美的。但我需要

我已经定义了一个
Foo
类,并在
Bar
类中使用它,带有一个事件处理程序:

public class Bar
{
    public Bar()
    {
        Foo foo = new Foo(); 
        foo.my_custom_event += my_event_handler; 
    }

    public void my_event_handler()
    {
        // do work here 
    }
}
这是完美的。但我需要在
Foo
类中定义一个方法,当我向
my_custom_event
添加事件处理程序时,该方法将被激发,如:

public class Foo
{
    ...
    public/private void my_event_handler_adder(target_function)
    {
         functions_that_are_fired_on_my_custom_event.Append(target_function); 
    }
}

有没有办法定义这种加法器方法

我们已经解决了这个问题,但我仍然不明白他们在那里谈论什么。这个问题不同于那个问题,因为这个问题更简单。
class Foo
{
    private EventHandler explicitEvent;
    public event EventHandler ExplicitEvent 
    {
       add 
       { 
           explicitEvent += value;
           FireNeededMethodHere();
       } 
       remove 
       { 
           explicitEvent -= value; 
       }
    }
}