I'm beginner to C#, I have code where by accident I declared events skipping event
keyword. I was sure that this is right code:
using System;
public class Player
{
...
private float money;
public Action<float> OnMoneyChanged; // missed `event` keyword.
private void SetMoney(float amount)
{
money = amount;
OnMoneyChanged?.Invoke(amount);
}
}
public class Level
{
public Level(Player player)
{
player.OnMoneyChanged += UpdateUi;
...
}
private void UpdateUi(float money)
{
....
}
}
And that's works perfect, no error, no bugs appear.
I knows that formally by skipping event
I didn't declare events but normal delegate
.
The only drawback I came out is that this mislead other programmer who will read the code, they may conclude that something strange happening here.
The question is: what are the long consequences of missing event
for delegate type?
What putting missing event
keyword changes?