Mono Class Library: System.Delegate Overview | Members

System.Delegate.Combine Method

Concatenates the invocation lists of the specified delegates. [Edit]

public static Delegate Combine (Delegate a, Delegate b)

Parameters

a
The delegate whose invocation list will be first in the invocation list of the new delegate. [Edit]
b
The delegate whose invocation list will be last in the invocation list of the new delegate. [Edit]

Returns

A delegate, or null .

The following table describes the value returned when a or b is null .

abReturn Value
nullnullnull
nullnon-nullb
non-nullnulla

When a and b are non-null, this method returns a new delegate with the concatenated invocation lists of a and b .

[Edit]

Exceptions

TypeReason
ArgumentExceptiona and b are not null and not of the same type. [Edit]

Remarks

Unless a or b is null , a and b are required to be the exact same type.

Consider the following situation, in which D1, D2, D3, D4, and D5 are delegate instances of the same type, D1's invocation list has one entry, E1, and D2's invocation list has one entry, E2.

Then, D3 = Combine(D1, D2) results in D3's having an invocation list of E1 + E2.

Then, D4 = Combine(D2, D1) results in D4's having an invocation list of E2 + E1.

Then, D5 = Combine(D3, D4) results in D5's having an invocation list of E1 + E2 + E2 + E1.

Note:

The invocation list of the returned delegate can contain duplicate methods.

Delegate.Combine(Delegate, Delegate) is useful for creating event handlers that call multiple methods each time an event occurs.

[Edit]

Requirements

Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0