Events - naming convention and style

后端 未结 7 681
北海茫月
北海茫月 2020-12-02 10:40

I\'m learning about Events / Delegates in C#. Could I ask your opinion on the naming/coding style I\'ve chosen (taken from the Head First C# book)?

Am teaching a fr

7条回答
  •  一生所求
    2020-12-02 11:05

    Looks good, aside from the fact that OnTick doesn't follow the typical event invocation model. Typically, On[EventName] raises the event a single time, like

    protected virtual void OnTick(EventArgs e)
    {
        if(Tick != null) Tick(this, e);
    }
    

    Consider creating this method, and renaming your existing "OnTick" method to "StartTick", and instead of invoking Tick directly from StartTick, call OnTick(EventArgs.Empty) from the StartTick method.

提交回复
热议问题