About This eBook by Bart De Smet

Safari, the world’s most comprehensive technology and business learning platform.

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required

O'Reilly logo

add and remove Accessors

With events based on a piece of metadata pointing at two methods, it shouldn’t be at all surprising that C# provides a way to customize those methods in case you want to do so. In the context of events (and properties), we refer to those methods as accessors. For events, two accessors exist called add and remove. The syntax is predictable, being analog to get and set for properties:

public event Finished {    add {        // Called when doing +=.    }    remove {        // Called when doing -=.    }}

Inside those accessors, the right side of the += and -= operator is available using the value keyword. This is similar to the way a property setter gets access to the value being assigned to ...

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required