This documentation is archived and is not being maintained.

7.9.8 Delegate equality operators

Visual Studio .NET 2003

Every delegate type implicitly provides the following predefined comparison operators:

bool operator ==(System.Delegate x, System.Delegate y);
bool operator !=(System.Delegate x, System.Delegate y);

Two delegate instances are considered equal as follows:

  • If either of the delegate instances is null, they are equal if and only if both are null.
  • If either of the delegate instances has an invocation list (Section 15.1) containing one entry, they are equal if and only if the other also has an invocation list containing one entry, and either:
    • both refer to the same static method, or
    • both refer to the same non-static method on the same target object.
  • If either of the delegate instances has an invocation list containing two or more entries, those instances are equal if and only if their invocation lists are the same length, and each entry in one's invocation list is equal to the corresponding entry, in order, in the other's invocation list.

Note that delegates of different types can be considered equal by the above definition, as long as they have the same return type and parameter types.

Show: