How to reference an event in C#

后端 未结 3 2026
陌清茗
陌清茗 2020-12-18 00:17

I have the following class, which has one public event called LengthChanged:

class Dimension
{
    public int Length
    {
        get
        {         


        
3条回答
  •  青春惊慌失措
    2020-12-18 01:16

    You can create a custom Accessor.

       public event EventHandler NewEvent
                {
                    add { Dimension.LengthChanged += value; }
                    remove { Dimension.LengthChanged -= value; }
                }
    

    Please See https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/events/how-to-implement-custom-event-accessors

提交回复
热议问题