.Net multiple event handlers per event that returns a value

If I have an event whose handler returns bool, what happens if I attach multiple events?

see this example

public class MyClass
{
 public delegate bool MyEventHandler(object sender, EventArgs e);
 public event MyEventHandler Submit;

 public void DoSubmissions()
 {
  if (Submit != null && Submit(this, null))
  {
   Console.Write("HOORAY");
  }
 }
}

therefore, in my example, the handler returns true on success. but I assign two event handlers ... what happens? is the first handler used? second? neither? as?

+3
source share
2 answers

The return value of the last recorded event is used.

+4
source

In general, this is a poor design.

, CancelEventArgs, EventArgs. / . A ref , , . IMO:

, , , .

, , , :

, , , .

, :

[] ,

, , , , .

+6

Source: https://habr.com/ru/post/1707980/


All Articles