Delegate.Combine 方法

定义

将指定的多路广播(可组合)委托的调用列表连接起来。Concatenates the invocation lists of the specified multicast (combinable) delegates.

重载

Combine(Delegate[])

将委托数组的调用列表连接在一起。Concatenates the invocation lists of an array of delegates.

Combine(Delegate, Delegate)

将两个委托的调用列表连接在一起。Concatenates the invocation lists of two delegates.

Combine(Delegate[])

将委托数组的调用列表连接在一起。Concatenates the invocation lists of an array of delegates.

public:
 static Delegate ^ Combine(cli::array <Delegate ^> ^ delegates);
[System.Runtime.InteropServices.ComVisible(true)]
public static Delegate Combine (Delegate[] delegates);
static member Combine : Delegate[] -> Delegate
Public Shared Function Combine (delegates As Delegate()) As Delegate

参数

delegates
Delegate[]

要组合的委托的数组。The array of delegates to combine.

返回

新的委托,该委托的调用列表将 delegates 数组中的委托的调用列表串联在一起。A new delegate with an invocation list that concatenates the invocation lists of the delegates in the delegates array. 如果 delegatesnulldelegates 包含零个元素,或 delegates 中的每个条目均为 null,则返回 nullReturns null if delegates is null, if delegates contains zero elements, or if every entry in delegates is null.

属性

异常

不是所有 delegates 中的非 null 项都是同一委托类型的实例。Not all the non-null entries in delegates are instances of the same delegate type.

注解

如果数组包含的条目为null,则忽略这些条目。 delegatesIf the delegates array contains entries that are null, those entries are ignored.

调用列表可以包含重复项;也就是说,引用相同对象上的同一方法的条目。The invocation list can contain duplicate entries; that is, entries that refer to the same method on the same object.

备注

与赋值兼容的泛型委托不一定是可组合的。Generic delegates that are assignment-compatible because of variance are not necessarily combinable. 要使其可组合,类型必须完全匹配。To be combinable, the types must match exactly. 例如,假设名Derived为的类派生自名Base为的类。For example, suppose that a class named Derived is derived from a class named Base. Action<Base> 协变和逆变中所述,可以将类型的委托(Action(Of Base)Action<Derived>Visual Basic 中)分配给类型的变量,但这两个委托无法组合,因为这些类型不完全匹配。A delegate of type Action<Base> (Action(Of Base) in Visual Basic) can be assigned to a variable of type Action<Derived>, as explained in Covariance and Contravariance, but the two delegates cannot be combined because the types do not match exactly.

Combine适用于创建每次发生事件时调用多个方法的事件处理程序。Combine is useful for creating event handlers that call multiple methods each time an event occurs.

安全性

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

另请参阅

Combine(Delegate, Delegate)

将两个委托的调用列表连接在一起。Concatenates the invocation lists of two delegates.

public:
 static Delegate ^ Combine(Delegate ^ a, Delegate ^ b);
public static Delegate Combine (Delegate a, Delegate b);
static member Combine : Delegate * Delegate -> Delegate
Public Shared Function Combine (a As Delegate, b As Delegate) As Delegate

参数

a
Delegate

最先出现其调用列表的委托。The delegate whose invocation list comes first.

b
Delegate

最后出现其调用列表的委托。The delegate whose invocation list comes last.

返回

新的委托,它的调用列表将 ab 的调用列表按该顺序连接在一起。A new delegate with an invocation list that concatenates the invocation lists of a and b in that order. 如果 bnull,则返回 a;如果 a 为 null 引用,则返回 b;如果 ab 均为 null 引用,则返回 null 引用。Returns a if b is null, returns b if a is a null reference, and returns a null reference if both a and b are null references.

异常

ab 均不为 null,且 ab 不是相同委托类型的实例。Both a and b are not null, and a and b are not instances of the same delegate type.

注解

调用列表可以包含重复项;也就是说,引用相同对象上的同一方法的条目。The invocation list can contain duplicate entries; that is, entries that refer to the same method on the same object.

备注

与赋值兼容的泛型委托不一定是可组合的。Generic delegates that are assignment-compatible because of variance are not necessarily combinable. 要使其可组合,类型必须完全匹配。To be combinable, the types must match exactly. 例如,假设名Derived为的类派生自名Base为的类。For example, suppose that a class named Derived is derived from a class named Base. Action<Base> 协变和逆变中所述,可以将类型的委托(Action(Of Base)Action<Derived>Visual Basic 中)分配给类型的变量,但这两个委托无法组合,因为这些类型不完全匹配。A delegate of type Action<Base> (Action(Of Base) in Visual Basic) can be assigned to a variable of type Action<Derived>, as explained in Covariance and Contravariance, but the two delegates cannot be combined because the types do not match exactly.

Combine适用于创建每次发生事件时调用多个方法的事件处理程序。Combine is useful for creating event handlers that call multiple methods each time an event occurs.

安全性

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

另请参阅

适用于