title: How do I unsubscribe all handlers from an event for a particular class in C#?
body: <p>Basic premise:</p>
  
  <p>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 all subscriptions for that room.</p>
  
  <p>How can I best unsubscribe the Avatar from all events in the room before I add the Avatar to a new Room and subscribe to the new Room's events?</p>
  
  <p>The code goes something like this:</p>
  
  <pre><code>class Room
  {
     public event EventHandler&lt;EnterRoomEventArgs&gt; AvatarEntersRoom;
     public event EvnetHandler&lt;LeaveRoomEventArgs&gt; AvatarLeavesRoom;
     public event EventHandler&lt;AnotherOfManyEventArgs&gt; AnotherOfManayAvatarEvents;
  
  
     public void AddPlayer(Avatar theAvatar)
     {
        AvatarEntersRoom(this, new EnterRoomEventArgs()); 
  
        AvatarEntersRoom += new EventHandler&lt;EnterRoomEventArgs&gt;(theAvatar.HandleAvatarEntersRoom);
  
        AvatarLeavesRoom += new EventHandler&lt;EnterRoomEventArgs&gt;(theAvatar.HandleAvatarEntersRoom);
  
        AnotherOfManayAvatarEvents += new EventHandler&lt;EnterRoomEventArgs&gt;(theAvatar.HandleAvatarEntersRoom);          
  
     }
  
  }
  
  class Avatar
  {
     public void HandleAvatarEntersRoom(object sender, EnterRoomEventArgs e)
     {
         Log.Write("avatar has entered the room");
     }
  
     public void HandleAvatarLeaveRoom(object sender, LeaveRoomEventArgs e)
     {
         Log.Write("avatar has left room");
     }
  
     public void HandleAnotherOfManayAvatarEvents(object sender, AnotherOfManyEventArgs e)
     {
         Log.Write("another avatar event has occurred");
     }
  }
  </code></pre>