Comparing delegates

delegates can be compared. A delegate overrides the equality operator (==) and the (!=) operator. These two operators in turn rely on the Equals method that is an overridden method for the delegate class. Similar to the way strings can be compared by value and not by reference, the Delegate class compares the value of the delegate rather than the reference. For a delegate, the value consists of the values exposed by the Method and Target properties seen in Listings 14.5 and 14.8. If the Method and Target properties are the same, then the delegates are considered to be equal. Two different instances will obviously have different Targets, so delegates defined on different instances will be considered different. In addition, ...

Get .NET Common Language Runtime Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.