14.9.8 Delegate equality operators

本文详细介绍了C#中委托类型的预定义比较操作符及其工作原理。包括如何判断两个委托实例是否相等,涉及到委托实例为null的情况、静态方法引用、非静态方法引用以及包含多个条目的调用列表的比较。
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.
C# LANGUAGE SPECIFICATION
168
?If either of the delegate instances has an invocation list (?2.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.
Delegates of different types can be considered equal by the above
definition, as long as they have the same
return type and parameter types.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值