How to reference an event in C#

后端 未结 3 2023
陌清茗
陌清茗 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:00

    Unfortunately there isn't really a way of doing this. Events aren't first class citizens in .NET in general - although F# tries to promote them there.

    Either pass in the subscribe/unsubscribe delegate or using a string indicating the name of the event. (The latter is often shorter, but obviously less safe at compile-time.)

    Those are the approaches which Reactive Extensions takes - if there were a cleaner way of doing it, I'm sure they would be using that :(

提交回复
热议问题