I'm wondering about something. Let's say I have an event named SomethingChanged with 2 parameters. first is the sender which fires the event. second one is just a number.
Case 1:
I defined this event in SenderClass
:
public event Action<SenderClass, int> SomethingChanged;
Normally I can attach the event handler like this:
item.SomethingChanged += (sender, p) =>
{
if (p == 1) sender.F1();
else sender.F2();
};
Case 2:
But if I remove the sender parameter:
public event Action<int> SomethingChanged;
it does not change a thing and I still can use it:
item.SomethingChanged += p =>
{
if (p == 1) item.F1();
else item.F2();
};
It's obvious to me that by removing sender the following usage is no longer feasible:
item.SomethingChanged += item_SomethingChanged;
private void item_SomethingChanged(SenderClass sender, int p)
{
if (p == 1) sender.F1();
else sender.F2();
}
Question:
But the thing I'm curious about is How the compiler finds about that sender in Case2? Does it use reflection or do they both translate into the same assembly code? Or?