remove (C# Reference)
The remove
contextual keyword is used to define a custom event accessor that is invoked when client code unsubscribes from your event. If you supply a custom remove
accessor, you must also supply an add accessor.
Example
The following example shows an event with custom add and remove
accessors. For the full example, see How to implement interface events.
class Events : IDrawingObject
{
event EventHandler PreDrawEvent;
event EventHandler IDrawingObject.OnDraw
{
add => PreDrawEvent += value;
remove => PreDrawEvent -= value;
}
}
You do not typically need to provide your own custom event accessors. The accessors that are automatically generated by the compiler when you declare an event are sufficient for most scenarios.
See also
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for