Action <> Event Vs Action

there is

public event Action delt = () => { Console.WriteLine("Information"); };

overloaded version

Action<int, int> delg = (a, b) => { Console.WriteLine( a + b); }; ?

I mean Action <> delegate - an overloaded version of "Action Action"?

+3
source share
3 answers

It is not called overload.

Basically, there is a set of types declared as follows:

namespace System {
    delegate void Action();
    delegate void Action<T>(T a);
    delegate void Action<T1, T2>(T1 a1, T2 a2);
    ...
}

Each of them is a different type, regardless of the other. The compiler knows what type you mean when you try to refer to it by the presence or absence <>after the type name and the number of type parameters inside <>.

event- a completely different matter, and does not participate in this. If you are confused by the difference between the event and the delegate, see the following two questions: 1 2

+5

"", "delt", EventHandler Action. , EvenHandler, (, MyHandler ( , InheritsFromEventArgs))

< > System.

+2
Strictly speaking, they are not equivalent. The first eventdeclares an anonymous function, and the second declares an anonymous function. Events like properties have special meaning in the CLR and follow some tips .
+1
source

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


All Articles