MulticastDelegate Class

 

Represents a multicast delegate; that is, a delegate that can have more than one element in its invocation list.

Namespace:   System
Assembly:  mscorlib (in mscorlib.dll)

System.Object
  System.Delegate
    System.MulticastDelegate

[<AbstractClass>]
[<SerializableAttribute>]
[<ComVisibleAttribute(true)>]
type MulticastDelegate = 
    class
        inherit Delegate
    end

NameDescription
System_CAPS_protmethodMulticastDelegate(Object, String)

Initializes a new instance of the MulticastDelegate class.

System_CAPS_protmethodMulticastDelegate(Type, String)

Initializes a new instance of the MulticastDelegate class.

NameDescription
System_CAPS_pubpropertyMethod

Gets the method represented by the delegate.(Inherited from Delegate.)

System_CAPS_pubpropertyTarget

Gets the class instance on which the current delegate invokes the instance method.(Inherited from Delegate.)

NameDescription
System_CAPS_pubmethodClone()

Creates a shallow copy of the delegate.(Inherited from Delegate.)

System_CAPS_protmethodCombineImpl(Delegate)

Combines this Delegate with the specified Delegate to form a new delegate.(Overrides Delegate.CombineImpl(Delegate).)

System_CAPS_pubmethodDynamicInvoke(Object[])

Dynamically invokes (late-bound) the method represented by the current delegate.(Inherited from Delegate.)

System_CAPS_protmethodDynamicInvokeImpl(Object[])

Dynamically invokes (late-bound) the method represented by the current delegate.(Inherited from Delegate.)

System_CAPS_pubmethodEquals(Object)

Determines whether this multicast delegate and the specified object are equal.(Overrides Delegate.Equals(Object).)

System_CAPS_protmethodFinalize()

Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)

System_CAPS_pubmethodGetHashCode()

Returns the hash code for this instance.(Overrides Delegate.GetHashCode().)

System_CAPS_pubmethodGetInvocationList()

Returns the invocation list of this multicast delegate, in invocation order.(Overrides Delegate.GetInvocationList().)

System_CAPS_protmethodGetMethodImpl()

Returns a static method represented by the current MulticastDelegate.(Overrides Delegate.GetMethodImpl().)

System_CAPS_pubmethodGetObjectData(SerializationInfo, StreamingContext)

Populates a SerializationInfo object with all the data needed to serialize this instance.(Overrides Delegate.GetObjectData(SerializationInfo, StreamingContext).)

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_protmethodMemberwiseClone()

Creates a shallow copy of the current Object.(Inherited from Object.)

System_CAPS_protmethodRemoveImpl(Delegate)

Removes an element from the invocation list of this MulticastDelegate that is equal to the specified delegate.(Overrides Delegate.RemoveImpl(Delegate).)

System_CAPS_pubmethodToString()

Returns a string that represents the current object.(Inherited from Object.)

NameDescription
System_CAPS_puboperatorSystem_CAPS_staticEquality(MulticastDelegate, MulticastDelegate)

Determines whether two MulticastDelegate objects are equal.

System_CAPS_puboperatorSystem_CAPS_staticInequality(MulticastDelegate, MulticastDelegate)

Determines whether two MulticastDelegate objects are not equal.

NameDescription
System_CAPS_pubmethodGetMethodInfo()

Gets an object that represents the method represented by the specified delegate.(Defined by RuntimeReflectionExtensions.)

MulticastDelegate is a special class. Compilers and other tools can derive from this class, but you cannot derive from it explicitly. The same is true of the Delegate class.

In addition to the methods that delegate types inherit from MulticastDelegate, the common language runtime provides two special methods: BeginInvoke and EndInvoke. For more information about these methods, see Calling Synchronous Methods Asynchronously.

A MulticastDelegate has a linked list of delegates, called an invocation list, consisting of one or more elements. When a multicast delegate is invoked, the delegates in the invocation list are called synchronously in the order in which they appear. If an error occurs during execution of the list then an exception is thrown.

The following example defines a class, StringContainer, which includes a collection of strings. One of its members is the CheckAndDisplayDelegate delegate, which is used to display strings stored in a StringContainer object that satisfy particular criteria. The delegate takes a single string as a parameter and returns void (or, in Visual Basic, it's a Sub procedure). It also includes a method, DisplayAllQualified, that has a single parameter, a CheckAndDisplayDelegate delegate. This allows the method to be called and to display a set of strings that are filtered based on the methods that the delegate contains.

The example also defines a utility class, StringExtensions, that has two methods:

  • ConStart, which displays strings that begin with a consonant.

  • VowelStart, which displays strings that begin with a vowel.

Note that both methods include a single string parameter and return void. In other words, both methods can be assigned to the CheckAndDisplayDelegate delegate.

The Test.Main method is the application entry point. It instantiates a StringContainer object, populates it with strings, and creates two CheckAndDisplayDelegate delegates, conStart and vowelStart, that invoke a single method. It then calls the Delegate.Combine method to create the multipleDelegates delegate, which initially contains the ConStart and VowelStart delegates. Note that when the multipleDelegates delegate is invoked, it displays all the strings in the collection in their original order. This is because each letter is passed separately to each delegate, and each letter meets the filtering criteria of only one of the two delegates. Finally, after calls to Delegate.Remove and Delegate.Combine, multipleDelegates contains two conStart delegates. When it is invoked, each string in the StringContainer object is displayed twice.

No code example is currently available or this language may not be supported.

Universal Windows Platform
Available since 8
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1

Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top
Show: