System.Delegate Class

Assembly: Mscorlib.dll
Namespace: System
Summary
Represents a delegate, which is a data structure that refers to a static method or to a class instance and an instance method of that class.
C# Syntax:
[Serializable]
public abstract class Delegate : ICloneable, ISerializable
Remarks
The Delegate class is the base class for delegate types. However, only the system and compilers can derive explicitly from the Delegate class or from the MulticastDelegate class. It is also not permissible to derive a new type from a delegate type. The Delegate class is not considered a delegate type; it is a class used to derive delegate types.

Most languages implement a delegate keyword, and compilers for those languages are able to derive from the MulticastDelegate class; therefore, users should use the delegate keyword provided by the language.

The declaration of a delegate type establishes a contract that specifies the signature of one or more methods. A delegate is an instance of a delegate type, and references one or more of the following:

A delegate can reference a method only if the signature of the method exactly matches the signature specified by the delegate type. When a delegate references an instance method, the delegate stores a reference to the method's entry point and a reference to an object, called the target, which is the class instance that the method is invoked on. The target of an instance method cannot be null. When a delegate references a static method, the delegate stores a reference to the method's entry point. The target of a static method is null.

The invocation list of a delegate is an ordered set of delegates in which each element of the list invokes exactly one of the methods invoked by the delegate. An invocation list can contain duplicate methods. During an invocation, a delegate invokes methods in the order in which they appear in the invocation list. A delegate attempts to invoke every method in its invocation list; duplicates are invoked once for each time they appear in the invocation list. Delegates are immutable; once created, the invocation list of a delegate does not change.

A delegate is either multicast (combinable) or singlecast (noncombinable). Multicast or combinable delegates invoke one or more methods, and can be used in combining operations. Singlecast or noncombinable delegates invoke exactly one method and cannot be used in combining operations. The invocation list of a singlecast delegate A contains a single element: a reference to A.

Combining operations, such as Delegate.Combine and Delegate.Remove, do not alter existing delegates. Instead, such an operation returns a new delegate that contains the results of the operation, an unchanged delegate, or null. A combining operation returns null when the result of the operation is a delegate that does not reference at least one method. A combining operation returns an unchanged delegate when the requested operation has no effect.

If an invoked method throws an exception, the method stops executing, the exception is passed back to the caller of the delegate, and remaining methods in the invocation list are not invoked. Catching the exception in the caller does not alter this behavior.

When the signature of the methods invoked by a delegate includes a return value, the delegate returns the return value of the last element in the invocation list. When the signature includes a parameter that is passed by reference, the final value of the parameter is the result of every method in the invocation list executing sequentially and updating the parameter's value.

Compilers provide two additional methods to the delegate: BeginInvoke and EndInvoke. For more information on these methods, see .

The closest equivalent of a delegate in C or C++ is a function pointer. However, a function pointer can only reference static functions, whereas a delegate can reference both static and instance methods. When the delegate references an instance method, the delegate stores not only a reference to the method's entry point, but also a reference to the class instance for which to invoke the method. Unlike function pointers, delegates are object-oriented, type-safe, and secure.

Example
The following example shows how to define a standard delegate.
 using System;
 public class SamplesDelegate  {
 
    // Declares a delegate for a method that takes in an int and returns a String.
    public delegate String myMethodDelegate( int myInt );
 
    // Defines some methods to which the delegate can point.
    public class mySubClass  {
 
       public static String myStringMethod ( int myInt )  {
          if ( myInt > 0 )
             return( "positive" );
          if ( myInt < 0 )
             return( "negative" );
          return ( "zero" );
       }
 
       public static String mySignMethod ( int myInt )  {
          if ( myInt > 0 )
             return( "+" );
          if ( myInt < 0 )
             return( "-" );
          return ( "" );
       }
    }
 
    public static void Main()  {
 
       // Creates one delegate for each method.
       myMethodDelegate myD1 = new myMethodDelegate( mySubClass.myStringMethod );
       myMethodDelegate myD2 = new myMethodDelegate( mySubClass.mySignMethod );
 
       // Invokes the delegates.
       Console.WriteLine( "{0} is {1}; use the sign \"{2}\".\n", 5, myD1( 5 ), myD2( 5 ) );
       Console.WriteLine( "{0} is {1}; use the sign \"{2}\".\n", -3, myD1( -3 ), myD2( -3 ) );
       Console.WriteLine( "{0} is {1}; use the sign \"{2}\".\n", 0, myD1( 0 ), myD2( 0 ) );
    }
 
 }
 /*
 Output:
 
 5 is positive; use the sign "+".
 -3 is negative; use the sign "-".
 0 is zero; use the sign "".
  */ 

    
See also:
System Namespace | MulticastDelegate

System.Delegate Member List:

Public Properties
Method Read-only

Gets the static method represented by the delegate.
Target Read-only

Gets the class instance on which the current delegate invokes the instance method.
Public Methods
Clone Creates a shallow copy of the delegate.
Combine Overloaded:
Combine(Delegate[] delegates)

Concatenates the invocation lists of an array of multicast (combinable) delegates.
Combine Overloaded:
Combine(Delegate a, Delegate b)

Concatenates the invocation lists of two multicast (combinable) delegates.
CreateDelegate Overloaded:
CreateDelegate(Type type, MethodInfo method)

Creates a delegate of the specified type to represent the specified static method.
CreateDelegate Overloaded:
CreateDelegate(Type type, object target, string method)

Creates a delegate of the specified type that represents the specified instance method to invoke on the specified class instance.
CreateDelegate Overloaded:
CreateDelegate(Type type, Type target, string method)

Creates a delegate of the specified type that represents the specified static method of the specified class.
CreateDelegate Overloaded:
CreateDelegate(Type type, object target, string method, bool ignoreCase)

Creates a delegate of the specified type that represents the specified instance method to invoke on the specified class instance with the specified case-sensitivity.
DynamicInvoke Dynamically invokes (late-bound) the method represented by the current delegate.
Equals Overridden:
Determines whether the specified object and the current singlecast (noncombinable) delegate share the same target, method, and invocation list.
GetHashCode Overridden:
Returns a hash code for the delegate.
GetInvocationList Returns the invocation list of the delegate.
GetObjectData Implements the ISerializable interface and returns the data needed to serialize the delegate.
GetType
(inherited from System.Object)
See base class member description: System.Object.GetType

Derived from System.Object, the primary base class for all objects.
Remove Removes the invocation list of a delegate from the invocation list of another delegate.
ToString
(inherited from System.Object)
See base class member description: System.Object.ToString

Derived from System.Object, the primary base class for all objects.
Public Operators and Type Conversions
op_Equality Determines whether the specified delegates are equal.
op_Inequality Determines whether the specified delegates are not equal.
Protected Constructors
ctor #1 Overloaded:
.ctor(object target, string method)

Initializes a delegate that invokes the specified instance method on the specified class instance.
ctor #2 Overloaded:
.ctor(Type target, string method)

Initializes a delegate that invokes the specified static method from the specified class.
Protected Methods
CombineImpl Concatenates the invocation lists of the specified multicast (combinable) delegate and the current multicast (combinable) delegate.
DynamicInvokeImpl Dynamically invokes (late-bound) the method represented by the current delegate.
Finalize
(inherited from System.Object)
See base class member description: System.Object.Finalize

Derived from System.Object, the primary base class for all objects.
GetMethodImpl Gets the static method represented by the current delegate.
MemberwiseClone
(inherited from System.Object)
See base class member description: System.Object.MemberwiseClone

Derived from System.Object, the primary base class for all objects.
RemoveImpl Removes the invocation list of a delegate from the invocation list of another delegate.

Hierarchy:


System.Delegate Member Details

Overloaded ctor #1
Summary
Initializes a delegate that invokes the specified instance method on the specified class instance.
C# Syntax:
protected Delegate(
   object target,
   string method
);
Parameters:

target

The class instance on which the delegate invokes method.

method

The name of the instance method that the delegate represents.

Exceptions
Exception Type Condition
ArgumentNullException target is null.

-or-

method is null.

Remarks
This constructor is called by a compiler-generated delegate type to create a delegate based on the name of an instance method and an instance of the class that defines that method.

This constructor creates delegates for instance methods only. An instance method is a method that is associated with an instance of a class; a static method is a method that is associated with the class itself.

See also:
Object | String

Return to top


Overloaded ctor #2
Summary
Initializes a delegate that invokes the specified static method from the specified class.
C# Syntax:
protected Delegate(
   Type target,
   string method
);
Parameters:

target

The Type representing the class that defines method.

method

The name of the static method that the delegate represents.

Exceptions
Exception Type Condition
ArgumentNullException target is null.

-or-

method is null.

Remarks
This constructor is called by a compiler-generated delegate type to create a delegate based on the name of a static method and the Type representing the class that defines that method.

This constructor creates delegates for static methods only. An instance method is a method that is associated with an instance of a class; a static method is a method that is associated with the class itself.

To get the Type that represents a class, use the Type.GetType method with the fully qualified (including namespace) name of the class. For example, passing "System.Threading.ThreadStart" to Type.GetType returns a Type for the ThreadStart class.

See also:
Type | String

Return to top


Property: Method (read-only)
Summary
Gets the static method represented by the delegate.
C# Syntax:
public MethodInfo Method {get;}
Exceptions
Exception Type Condition
MemberAccessException The caller does not have access to the method represented by the delegate (for example, if the method is private).
Remarks
This property applies only if the current delegate represents a static method.
See also:
MethodInfo | Delegate.GetMethodImpl

Return to top


Property: Target (read-only)
Summary
Gets the class instance on which the current delegate invokes the instance method.
C# Syntax:
public object Target {get;}
Remarks
An instance method is a method that is associated with an instance of a class; a static method is a method that is associated with the class itself.

If the delegate invokes one or more instance methods, this property returns the target of the last instance method in the invocation list.

Return to top


Method: Clone()
Summary
Creates a shallow copy of the delegate.
C# Syntax:
public virtual object Clone();
Return Value:
A shallow copy of the delegate.
Implements:
ICloneable.Clone
Remarks
The clone has the same Type, target, method, and invocation list as the original delegate.

A shallow copy creates a new instance of the same type as the original object, and then copies the non-static fields of the original object. If the field is a value type, a bit-by-bit copy of the field is performed. If the field is a reference type, the reference is copied but the referred object is not; therefore, the reference in the original object and the reference in the clone point to the same object. In contrast, a deep copy of an object duplicates everything directly or indirectly referenced by the fields in the object.

Return to top


Overloaded Method: Combine(
   Delegate[] delegates
)
Summary
Concatenates the invocation lists of an array of multicast (combinable) delegates.
C# Syntax:
public static Delegate Combine(
   Delegate[] delegates
);
Parameters:

delegates

The array of multicast (combinable) delegates to combine.

Return Value:
A new multicast (combinable) delegate with an invocation list that concatenates the invocation lists of the delegates in the delegates array.

-or-

null, if delegates is null, if delegates contains zero elements, or if every entry in delegates is null.

Exceptions
Exception Type Condition
ArgumentException Not all the non-null entries in delegates are instances of the same delegate type.
MulticastNotSupportedException One or more non-null entries in delegates are singlecast (noncombinable) delegates.
Remarks
If 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.

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

See also:
MulticastDelegate | Delegate.CombineImpl

Return to top


Overloaded Method: Combine(
   Delegate a,
   Delegate b
)
Summary
Concatenates the invocation lists of two multicast (combinable) delegates.
C# Syntax:
public static Delegate Combine(
   Delegate a,
   Delegate b
);
Parameters:

a

The multicast (combinable) delegate whose invocation list comes first.

b

The multicast (combinable) delegate whose invocation list comes last.

Return Value:
A new multicast (combinable) delegate with an invocation list that concatenates the invocation lists of a and b in that order.

-or-

a, if b is null.

-or-

b, if a is null.

-or-

null, if both a and b are null.

Exceptions
Exception Type Condition
ArgumentException Both a and b are not null, and a and b are not instances of the same delegate type.
MulticastNotSupportedException Both a and b are not null and are singlecast (noncombinable) delegates.
Remarks
The invocation list can contain duplicate entries; that is, entries that refer to the same method on the same object.

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

See also:
MulticastDelegate | Delegate.CombineImpl

Return to top


Method: CombineImpl(
   Delegate d
)
Summary
Concatenates the invocation lists of the specified multicast (combinable) delegate and the current multicast (combinable) delegate.
C# Syntax:
protected virtual Delegate CombineImpl(
   Delegate d
);
Parameters:

d

The multicast (combinable) delegate whose invocation list to append to the end of the invocation list of the current multicast (combinable) delegate.

Return Value:
A new multicast (combinable) delegate with an invocation list that concatenates the invocation list of the current multicast (combinable) delegate and the invocation list of d.

-or-

The current multicast (combinable) delegate, if d is null.

Exceptions
Exception Type Condition
MulticastNotSupportedException Always thrown.
Remarks
This method applies only if the current delegate is multicast (combinable).

The current implementation simply throws a MulticastNotSupportedException.

The invocation list can contain duplicate entries; that is, entries that refer to the same method on the same object.

See also:
Delegate.Combine

Return to top


Overloaded Method: CreateDelegate(
   Type type,
   MethodInfo method
)
Summary
Creates a delegate of the specified type to represent the specified static method.
C# Syntax:
public static Delegate CreateDelegate(
   Type type,
   MethodInfo method
);
Parameters:

type

The Type of delegate to create.

method

The MethodInfo describing the static method for which the delegate is to be created.

Return Value:
A delegate of the specified type to represent the specified static method.
Exceptions
Exception Type Condition
ArgumentNullException type is null. -or-

method is null.

ArgumentException type does not inherit from either Delegate or MulticastDelegate.

-or-

method is not a static method.

InvalidProgramException The Invoke method of type is not found.
MemberAccessException The caller does not have access to the method represented by the delegate (for example, if the method is private).
SecurityException method is outside the current assembly and the caller does not have ReflectionPermission for the assembly containing method.
Remarks
This method creates delegates for static methods only. An instance method is a method that is associated with an instance of a class; a static method is a method that is associated with the class itself.

To get the Type that represents a class, use the Type.GetType method with the fully qualified (including namespace) name of the class. For example, passing "System.Threading.ThreadStart" to Type.GetType returns a Type for the ThreadStart class.

.NET Framework Security:
ReflectionPermissionFlag.MemberAccess for access to the method represented by the delegate.
See also:
Type | MulticastDelegate | ReflectionPermission | MethodInfo

Return to top


Overloaded Method: CreateDelegate(
   Type type,
   object target,
   string method
)
Summary
Creates a delegate of the specified type that represents the specified instance method to invoke on the specified class instance.
C# Syntax:
public static Delegate CreateDelegate(
   Type type,
   object target,
   string method
);
Parameters:

type

The Type of delegate to create.

target

The class instance on which method is invoked.

method

The name of the instance method that the delegate is to represent.

Return Value:
A delegate of the specified type that represents the specified instance method to invoke on the specified class instance.
Exceptions
Exception Type Condition
ArgumentNullException type is null.

-or-

target is null.

-or-

method is null.

ArgumentException type does not inherit from either Delegate or MulticastDelegate.

-or-

method is not an instance method.

MemberAccessException The caller does not have access to the method represented by the delegate (for example, if the method is private).
SecurityException method is outside the current assembly and the caller does not have ReflectionPermission for the assembly containing method.
Remarks
This method creates delegates for instance methods only. An instance method is a method that is associated with an instance of a class; a static method is a method that is associated with the class itself.

To get the Type that represents a class, use the Type.GetType method with the fully qualified (including namespace) name of the class. For example, passing "System.Threading.ThreadStart" to Type.GetType returns a Type for the ThreadStart class.

.NET Framework Security:
ReflectionPermissionFlag.MemberAccess for access to the method represented by the delegate.
See also:
Type | MulticastDelegate | ReflectionPermission | Object

Return to top


Overloaded Method: CreateDelegate(
   Type type,
   Type target,
   string method
)
Summary
Creates a delegate of the specified type that represents the specified static method of the specified class.
C# Syntax:
public static Delegate CreateDelegate(
   Type type,
   Type target,
   string method
);
Parameters:

type

The Type of delegate to create.

target

The Type representing the class that implements method. The Type representing the class that implements method.

method

The name of the static method that the delegate is to represent.

Return Value:
A delegate of the specified type that represents the specified static method of the specified class.
Exceptions
Exception Type Condition
ArgumentNullException type is null. -or-

target is null.

-or-

method is null.

ArgumentException type does not inherit from either Delegate or MulticastDelegate.

-or-

method is not a static method.

MemberAccessException The caller does not have access to the method represented by the delegate (for example, if the method is private).
SecurityException method is outside the current assembly and the caller does not have ReflectionPermission for the assembly containing method.
Remarks
This method creates delegates for static methods only. An instance method is a method that is associated with an instance of a class; a static method is a method that is associated with the class itself.

To get the Type that represents a class, use the Type.GetType method with the fully qualified (including namespace) name of the class. For example, passing "System.Threading.ThreadStart" to Type.GetType returns a Type for the ThreadStart class.

.NET Framework Security:
ReflectionPermissionFlag.MemberAccess for access to the method represented by the delegate.
See also:
Type | MulticastDelegate | ReflectionPermission | Object

Return to top


Overloaded Method: CreateDelegate(
   Type type,
   object target,
   string method,
   bool ignoreCase
)
Summary
Creates a delegate of the specified type that represents the specified instance method to invoke on the specified class instance with the specified case-sensitivity.
C# Syntax:
public static Delegate CreateDelegate(
   Type type,
   object target,
   string method,
   bool ignoreCase
);
Parameters:

type

The Type of delegate to create.

target

The class instance on which method is invoked.

method

The name of the instance method that the delegate is to represent.

ignoreCase

A Boolean indicating whether to ignore the case when comparing the name of the method.

Return Value:
A delegate of the specified type that represents the specified instance method to invoke on the specified class instance.
Exceptions
Exception Type Condition
ArgumentNullException type is null.

-or-

target is null.

-or-

method is null.

ArgumentException type does not inherit from either Delegate or MulticastDelegate.

-or-

method is not an instance method.

MemberAccessException The caller does not have access to the method represented by the delegate (for example, if the method is private).
SecurityException method is outside the current assembly and the caller does not have ReflectionPermission for the assembly containing method.
Remarks
This method creates delegates for instance methods only. An instance method is a method that is associated with an instance of a class; a static method is a method that is associated with the class itself.

To get the Type that represents a class, use the Type.GetType method with the fully qualified (including namespace) name of the class. For example, passing "System.Threading.ThreadStart" to Type.GetType returns a Type for the ThreadStart class.

.NET Framework Security:
ReflectionPermissionFlag.MemberAccess for access to the method represented by the delegate.
See also:
Type | MulticastDelegate | ReflectionPermission | Object

Return to top


Method: DynamicInvoke(
   object[] args
)
Summary
Dynamically invokes (late-bound) the method represented by the current delegate.
C# Syntax:
public object DynamicInvoke(
   object[] args
);
Parameters:

args

An array of objects that are the arguments to pass to the method represented by the current delegate.

-or-

null, if the method represented by the current delegate does not require arguments.

An array of objects that are the arguments to pass to the method represented by the current delegate.

-or-

null, if the method represented by the current delegate does not require arguments.

Return Value:
The object returned by the method represented by the delegate.
Exceptions
Exception Type Condition
MemberAccessException The caller does not have access to the method represented by the delegate (for example, if the method is private).

-or-

The number, order, or type of parameters listed in args is invalid.

TargetException The method represented by the delegate is an instance method and the target object is null.

-or-

The method represented by the delegate is invoked on an object or a class that does not support it.

TargetInvocationException One of the encapsulated methods throws an exception.
Remarks
This method calls the Delegate.DynamicInvokeImpl method.
See also:
Delegate.DynamicInvokeImpl | Object

Return to top


Method: DynamicInvokeImpl(
   object[] args
)
Summary
Dynamically invokes (late-bound) the method represented by the current delegate.
C# Syntax:
protected virtual object DynamicInvokeImpl(
   object[] args
);
Parameters:

args

An array of objects that are the arguments to pass to the method represented by the current delegate.

-or-

null, if the method represented by the current delegate does not require arguments.

An array of objects that are the arguments to pass to the method represented by the current delegate.

-or-

null, if the method represented by the current delegate does not require arguments.

Return Value:
The object returned by the method represented by the delegate.
Exceptions
Exception Type Condition
MemberAccessException The caller does not have access to the method represented by the delegate (for example, if the method is private).

-or-

The number, order, or type of parameters listed in args is invalid.

TargetException The method represented by the delegate is an instance method and the target object is null.

-or-

The method represented by the delegate is invoked on an object or a class that does not support it.

TargetInvocationException One of the encapsulated methods throws an exception.
Remarks
This method implements the Delegate.DynamicInvoke method.
See also:
Delegate.DynamicInvoke | Object

Return to top


Overridden Method: Equals(
   object obj
)
Summary
Determines whether the specified object and the current singlecast (noncombinable) delegate share the same target, method, and invocation list.
C# Syntax:
public override bool Equals(
   object obj
);
Parameters:

obj

The object to compare with the current singlecast (noncombinable) delegate.

Return Value:
true if obj and the current delegate have the same target, method, and invocation list; otherwise, false.
Exceptions
Exception Type Condition
MemberAccessException The caller does not have access to the method represented by the delegate (for example, if the method is private).
Remarks
This method applies only if the current delegate is singlecast (noncombinable).

Two delegates with the same methods, the same targets, and the same invocation lists are considered equal, even if they are not both multicast (combinable) or both singlecast (noncombinable).

The methods and targets are compared for equality as follows:

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.

See also:
Object

Return to top


Method: Finalize()
Inherited
See base class member description: System.Object.Finalize
C# Syntax:
~Delegate();

For more information on members inherited from System.Object click on the link above.

Return to top


Overridden Method: GetHashCode()
Summary
Returns a hash code for the delegate.
C# Syntax:
public override int GetHashCode();
Return Value:
A hash code for the delegate.
Remarks
The return value of this method must not be persisted for two reasons. First, the hash function of a class might be altered to generate a better distribution, rendering any values from the old hash function useless. Second, the default implementation of this class does not guarantee that the same value will be returned by different instances.
See also:
Object.GetHashCode

Return to top


Method: GetInvocationList()
Summary
Returns the invocation list of the delegate.
C# Syntax:
public virtual Delegate[] GetInvocationList();
Return Value:
An array of singlecast (noncombinable) delegates representing the invocation list of the current delegate. If the current delegate is singlecast (noncombinable), the array contains only one element, which is a reference to the current delegate. If the current delegate is multicast (combinable), the array contains one or more elements.
Remarks
Because the returned array contains only singlecast (noncombinable) delegates, the invocation list of each element is guaranteed to have exactly one entry.

The order of the delegates in the array is the same order in which the current delegate invokes the methods that those delegates represent.

Return to top


Method: GetMethodImpl()
Summary
Gets the static method represented by the current delegate.
C# Syntax:
protected virtual MethodInfo GetMethodImpl();
Return Value:
A MethodInfo describing the static method represented by the current delegate.
Exceptions
Exception Type Condition
MemberAccessException The caller does not have access to the method represented by the delegate (for example, if the method is private).
Remarks
This method applies only if the current delegate represents a static method.
See also:
MethodInfo | Delegate.Method

Return to top


Method: GetObjectData(
   SerializationInfo info,
   StreamingContext context
)
Summary
Implements the ISerializable interface and returns the data needed to serialize the delegate.
C# Syntax:
public virtual void GetObjectData(
   SerializationInfo info,
   StreamingContext context
);
Parameters:

info

A SerializationInfo containing information required to serialize the delegate.

context

A StreamingContext containing the source and destination of the serialized stream associated with the delegate.

Exceptions
Exception Type Condition
ArgumentNullException info is null.
Implements:
ISerializable.GetObjectData
See also:
ISerializable | SerializationInfo | StreamingContext

Return to top


Method: GetType()
Inherited
See base class member description: System.Object.GetType
C# Syntax:
public Type GetType();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: MemberwiseClone()
Inherited
See base class member description: System.Object.MemberwiseClone
C# Syntax:
protected object MemberwiseClone();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: op_Equality(
   Delegate d1,
   Delegate d2
)
Summary
Determines whether the specified delegates are equal.
C# Syntax:
public static bool operator ==(
   Delegate d1,
   Delegate d2
);
Parameters:

d1

The first delegate to compare.

d2

The second delegate to compare.

Return Value:
true if d1 is equal to d2; otherwise, false.
Remarks
Two delegates with the same methods, the same targets, and the same invocation lists are considered equal, even if they are not both multicast (combinable) or both singlecast (noncombinable).

The methods and targets are compared for equality as follows:

Two invocation lists are considered identical if they have the same order and the corresponding elements from the two lists represent the same method and target.

See also:
Delegate.Equals

Return to top


Method: op_Inequality(
   Delegate d1,
   Delegate d2
)
Summary
Determines whether the specified delegates are not equal.
C# Syntax:
public static bool operator !=(
   Delegate d1,
   Delegate d2
);
Parameters:

d1

The first delegate to compare.

d2

The second delegate to compare.

Return Value:
true if d1 is not equal to d2; otherwise, false.
Remarks
Two delegates are considered not equal if they have different methods, different targets, or different invocation lists.

The methods and targets are compared for equality as follows:

Two invocation lists are not equal if they have different sizes, if they are ordered differently, or if at least one element from one list represents a method or target that is different from that represented by its corresponding element in the other list.

See also:
Delegate.Equals

Return to top


Method: Remove(
   Delegate source,
   Delegate value
)
Summary
Removes the invocation list of a delegate from the invocation list of another delegate.
C# Syntax:
public static Delegate Remove(
   Delegate source,
   Delegate value
);
Parameters:

source

The delegate from which to remove the invocation list of value.

value

The delegate that supplies the invocation list to remove from the invocation list of source.

Return Value:
A new delegate with an invocation list formed by taking the invocation list of source and removing the invocation list of value, if the invocation list of value is found within the invocation list of source.

-or-

source, if value is null, or if the invocation list of value is not found within the invocation list of source.

-or-

null, if the invocation list of value is equal to the invocation list of source, or if source is null.

Exceptions
Exception Type Condition
MemberAccessException The caller does not have access to the method represented by the delegate (for example, if the method is private).
Remarks
If the invocation list of value matches a contiguous set of elements in the invocation list of source, then the invocation list of value is said to occur within the invocation list of source. If the invocation list of value occurs more than once in the invocation list of source, the last occurrence is removed.
See also:
Delegate.RemoveImpl | Delegate.Equals

Return to top


Method: RemoveImpl(
   Delegate d
)
Summary
Removes the invocation list of a delegate from the invocation list of another delegate.
C# Syntax:
protected virtual Delegate RemoveImpl(
   Delegate d
);
Parameters:

d

The delegate that supplies the invocation list to remove from the invocation list of the current delegate.

Return Value:
A new delegate with an invocation list formed by taking the invocation list of the current delegate and removing the invocation list of value, if the invocation list of value is found within the current delegate's invocation list.

-or-

The current delegate, if value is null, or if the invocation list of value is not found within the current delegate's invocation list.

-or-

null, if the invocation list of value is equal to the current delegate's invocation list.

Exceptions
Exception Type Condition
MemberAccessException The caller does not have access to the method represented by the delegate (for example, if the method is private).
Remarks
If the invocation list of value matches a contiguous set of elements in the current delegate's invocation list, then the invocation list of value is said to occur within the current delegate's invocation list. If the invocation list of value occurs more than once in the current delegate's invocation list, the last occurrence is removed.
See also:
Delegate.Remove | Delegate.Equals

Return to top


Method: ToString()
Inherited
See base class member description: System.Object.ToString
C# Syntax:
public virtual string ToString();

For more information on members inherited from System.Object click on the link above.

Return to top


Top of page

Copyright (c) 2002 Microsoft Corporation. All rights reserved.