Code Inspection: Delegate subtractions
The .NET framework defines operator overloads for the
- operators on the
Delegate data type. The
+ operator effectively combines delegates so that a multiple delegates are called within one. The
- operator, on the other hand, attempts to remove the delegate invocation list from a delegate.
The list distinction is important here: what this implies is that subtraction of a delegate effectively implies a subtraction of lists. For example, in the code below, removing the
C delegates from the ABC invocation list via the expression
s - (a + c) has no effect whatsoever, because
AC is not a sublist of
It is also worth noting that sublist removal happens from the end of the list. For example:
Since the above mechanics can lead to unpredictable results, ReSharper issues a warning whenever it encounters a delegate subtraction operator.