Delegate.Equals(Object) 方法

定义

确定指定的对象和当前委托的类型是否相同,是否共享相同的目标、方法和调用列表。Determines whether the specified object and the current delegate are of the same type and share the same targets, methods, and invocation list.

public:
 override bool Equals(System::Object ^ obj);
public override bool Equals (object obj);
override this.Equals : obj -> bool
Public Overrides Function Equals (obj As Object) As Boolean

参数

obj
Object

要与当前委托进行比较的对象。The object to compare with the current delegate.

返回

如果 obj 和当前委托具有相同的目标、方法和调用列表,则为 true;否则为 falsetrue if obj and the current delegate have the same targets, methods, and invocation list; otherwise, false.

异常

调用方不能访问由委托表示的方法(例如,在方法为私有方法的情况下)。The caller does not have access to the method represented by the delegate (for example, if the method is private).

注解

如果两个委托的类型不同,则不会将它们视为相等。If the two delegates are not of the same type, they are not considered equal.

重要

在 .NET Framework 版本1.0 和1.1 中,如果两个委托的目标、方法和调用列表相等,即使这些委托属于不同类型,也被视为相等。In the .NET Framework version 1.0 and 1.1, two delegates were considered equal if their targets, methods, and invocation list were equal, even if the delegates were of different types.

比较方法和目标的相等性,如下所示:The methods and targets are compared for equality as follows:

  • 如果所比较的两个方法都是静态的,并且在同一类上是相同的方法,则这些方法被视为相等,并且目标也被视为相等。If the two methods being compared are both static and are the same method on the same class, the methods are considered equal and the targets are also considered equal.

  • 如果所比较的两个方法是实例方法,并且在同一对象上是相同的方法,则这些方法被视为相等,并且目标也被视为相等。If the two methods being compared are instance methods and are the same method on the same object, the methods are considered equal and the targets are also considered equal.

  • 否则,这些方法不会被视为相等,也不会将目标视为相等。Otherwise, the methods are not considered to be equal and the targets are also not considered to be equal.

仅当两个调用列表具有相同的顺序,并且两个列表中的相应元素表示相同的方法和目标时,两个调用列表才被视为相同。Two invocation lists are considered identical only if they have the same order and the corresponding elements from the two lists represent the same method and target.

安全性

ReflectionPermission
当通过诸如InvokeMember(String, BindingFlags, Binder, Object, Object[], ParameterModifier[], CultureInfo, String[])等机制后期绑定调用时。when invoked late-bound through mechanisms such as InvokeMember(String, BindingFlags, Binder, Object, Object[], ParameterModifier[], CultureInfo, String[]). 关联的枚举:MemberAccessAssociated enumeration: MemberAccess

适用于

另请参阅