How do I unsubscribe all handlers from an event for a particular class in C#?

后端 未结 5 1592
滥情空心
滥情空心 2020-12-08 07:04

Basic premise:

I have a Room which publishes an event when an Avatar \"enters\" to all Avatars within the Room. When an Avatar leaves the Room I want it to remove a

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-08 07:21

    Probably the simplest way to accomplish this would be to store all of your subscribed events for an avatar in an ArrayList of delegates to the events.

    When the avatar leaves the room, simply loop through the list of delegates performing a standard remove (-=).

提交回复
热议问题