How to subscribe an EventHandler? [Answered]

I don't understand how to subscribe this. I don't get it. I honestly don't even know why I used an EventHandler instead of an Action or something.
CharberryTree tree = new CharberryTree();
while (true)
tree.MaybeGrow();

public class CharberryTree
{
    public event EventHandler<RipenedEventArgs>? Ripened;

    public CharberryTree()
    {

    }
    private Random _random = new Random();
    public bool Ripe { get; set; }
    public void MaybeGrow()
    {
        // Only a tiny chance of ripening each time, but we try a lot!
        if (_random.NextDouble() < 0.00000001 && !Ripe)
        {
            Ripe = true;
            Ripened?.Invoke(this, new RipenedEventArgs(Ripe));
        }
    }
}

public class Notifier
{
    public Notifier(CharberryTree tree)
    {
        tree.Ripened += OnRipened();
    }
    public void OnRipened()
    {

    }
}

public class Harvester
{
    public Harvester(CharberryTree tree)
    {
        
    }
}

public class RipenedEventArgs : EventArgs
{
    public bool Ripe { get; set; }
    public RipenedEventArgs(bool ripe) => Ripe = ripe;
}
Was this page helpful?