Add event handler during object initialization

后端 未结 2 591
半阙折子戏
半阙折子戏 2021-01-21 23:39

I need to pass a instance (which will be created in this very moment) of a certain type to a method. This type offers several events which I\'d like to subscribe to too, so my c

2条回答
  •  独厮守ぢ
    2021-01-22 00:29

    This is not possible right now but according to Roslyn it is planned and might be available in the future.

    --------------------------------------------------------------------------
    | Feature            | Example                                |   C#     |
    -------------------------------------------------------------------------|
    | Event initializers |  new Customer { Notify += MyHandler }; | Planned  |
    -------------------------------------------------------------------------|
    

提交回复
热议问题