Why do we need events for a callback?

We can call callback methods using delegates. For instance,

public delegate bool ContinueProcessing ();

// later in the code we can write

ContinueProcessing cp = new ContinueProcessing (IsDataAvailable);

cp + = new ContinueProcessing (IsTransactionComplete);

// later in the method code definition

bool IsDataAvailable () {return true; }

bool IsTransactionComplete () {return true; }

cp.Invoke ();

The above call will call two Boolean methods one after another. Why do we need "events"? What is the purpose of "events"?

+3
source share
3 answers

- , , .

" , ", /.

. .

+9

. : , , ..

- , .

- (), , - , / / .

0

It seems that the keyword "event" is a delegate declaration modifier that allows it to be included in the interface, restricts it to a call inside the class that declares it, provides it with a couple of custom accessors (add and remove) and forces the delegate's signature (when used within .NET platform).

0
source

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


All Articles