BCL mscorlib [00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 ] 1.0.5000.0 2.0.0.0 4.0.0.0 System.Object System.ICloneable System.Runtime.Serialization.ISerializable System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDual) System.Runtime.InteropServices.ComVisible(true)

The following example creates two delegates. The first delegate invokes a static method, and the second invokes an instance method on a target object.

`using System; public delegate string DelegatedMethod(string s); class MyClass { public static string StaticMethod(string s) { return ("Static method Arg=" + s); } public string InstanceMethod(string s) { return ("Instance method Arg=" + s); } } class TestClass { public static void Main() { MyClass myInstance = new MyClass(); //Create delegates from delegate type DelegatedMethod. DelegatedMethod delStatic = new DelegatedMethod(MyClass.StaticMethod); DelegatedMethod delInstance = new DelegatedMethod(myInstance.InstanceMethod); //Invoke the methods referenced by the delegates. Console.WriteLine (delStatic("Call 1")); Console.WriteLine (delInstance ("Call 2")); } }`

The output is

Static method Arg=Call 1

Instance method Arg=Call 2

The following example shows the return value and the final value of a parameter that is passed by reference to a delegate that invokes multiple methods.

`using System; class MyClass { public int Increment(ref int i) { Console.WriteLine("Incrementing {0}",i); return (i++); } public int Negate(ref int i) { Console.WriteLine("Negating {0}",i); i = i * -1; return i; } } public delegate int DelegatedMethod(ref int i); class TestClass { public static void Main() { MyClass myInstance = new MyClass(); DelegatedMethod delIncrementer = new DelegatedMethod(myInstance.Increment); DelegatedMethod delNegater = new DelegatedMethod(myInstance.Negate); DelegatedMethod d = (DelegatedMethod) Delegate.Combine(delIncrementer, delNegater); int i = 1; Console.WriteLine("Invoking delegate using ref value {0}",i); int retvalue = d(ref i); Console.WriteLine("After Invoking delegate i = {0} return value is {1}",i, retvalue); } }`

The output is

Invoking delegate using ref value 1

Incrementing 1

Negating 2

After Invoking delegate i = -2 return value is -2

The class is the base class for delegate types. However, only the system and compilers can derive explicitly from the class or from the class. It is also not permissible to derive a new type from a delegate type. The 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 class; therefore, users should use the delegate keyword provided by the language.

The common language runtime provides an Invoke method for each delegate type, with the same signature as the delegate. You do not have to call this method explicitly from C#, Visual Basic, or Visual C++, because the compilers call it automatically. The Invoke method is useful in reflection when you want to find the signature of the delegate type.

The common language runtime provides each delegate type with BeginInvoke and EndInvoke methods, to enable asynchronous invocation of the delegate. For more information about these methods, see Calling Synchronous Methods Asynchronously.

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 that has references to:

An instance method of a type and a target object assignable to that type.

An instance method of a type, with the hidden parameter exposed in the formal parameter list. The delegate is said to be an open instance delegate.

A static method.

A static method and a target object assignable to the first parameter of the method. The delegate is said to be closed over its first argument.

For more information on delegate binding, see the method overload.

In the .NET Framework versions 1.0 and 1.1, a delegate can represent a method only if the signature of the method exactly matches the signature specified by the delegate type. Thus, only the first and third bullets in the preceding list are supported, and the first bullet requires an exact type match.

When a delegate represents an instance method closed over its first argument (the most common case), the delegate stores a reference to the method's entry point and a reference to an object, called the target, which is of a type assignable to the type that defined the method. When a delegate represents an open instance method, it stores a reference to the method's entry point. The delegate signature must include the hidden parameter in its formal parameter list; in this case, the delegate does not have a reference to a target object, and a target object must be supplied when the delegate is invoked.

When a delegate represents a static method, the delegate stores a reference to the method's entry point. When a delegate represents a static method closed over its first argument, the delegate stores a reference to the method's entry point and a reference to a target object assignable to the type of the method's first argument. When the delegate is invoked, the first argument of the static method receives the target object.

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 represented by the delegate. An invocation list can contain duplicate methods. During an invocation, methods are invoked 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.

Delegates are referred to as multicast, or combinable, because a delegate can invoke one or more methods and can be used in combining operations.

Combining operations, such as and , 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.

Managed languages use the and methods to implement delegate operations. Examples include the AddHandler and RemoveHandler statements in Visual Basic and the += and -= operators on delegate types in C#.

Starting with the net_v40_long, generic delegate types can have variant type parameters. Contravariant type parameters can be used as parameter types of the delegate, and a covariant type parameter can be used as the return type. This feature allows generic delegate types that are constructed from the same generic type definition to be assignment-compatible if their type arguments are reference types with an inheritance relationship, as explained in Covariance and Contravariance in Generics.

Generic delegates that are assignment-compatible because of variance are not necessarily combinable. To be combinable, the types must match exactly. For example, suppose that a class named Derived is derived from a class named Base. A delegate of type Action<Base> (Action(Of Base) in Visual Basic) can be assigned to a variable of type Action<Derived>, but the two delegates cannot be combined because the types do not match exactly.

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.

The closest equivalent of a delegate in C or C++ is a function pointer. A delegate can represent a static method or an instance method. When the delegate represents an instance method, the delegate stores not only a reference to the method's entry point, but also a reference to the class instance. Unlike function pointers, delegates are object oriented and type safe.

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.

- Constructor
  1.0.5000.0
  2.0.0.0
  4.0.0.0

  This constructor cannot be used in application code. To create a delegate by specifying the name of an instance method, use an overload of the method that specifies a method name and a target object. For example, the method overload creates a delegate for an instance method with a specified name.

  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.

  Initializes a delegate that invokes the specified instance method on the specified class instance.

  The class instance on which the delegate invokes .
  The name of the instance method that the delegate represents.
- Constructor
  1.0.5000.0
  2.0.0.0
  4.0.0.0

  This constructor cannot be used in application code. To create a delegate by specifying the name of a static method, use an overload of the method that specifies a method name but does not specify a target object. For example, the method overload creates a static delegate for a method with a specified name.

  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.

  Initializes a delegate that invokes the specified static method from the specified class.

  The representing the class that defines .
  The name of the static method that the delegate represents.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Object

  The clone has the same , 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 nonstatic 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.

  Creates a shallow copy of the delegate.

  A shallow copy of the delegate.

  0
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Runtime.InteropServices.ComVisible(true)
  System.Delegate `System.ParamArray`

  The non- delegates in are not of the same type.

  If the 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. For example, suppose that a class named Derived is derived from a class named Base. 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 in Generics, but the two delegates cannot be combined because the types do not match exactly.

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

  Concatenates the invocation lists of an array of delegates.

  A new delegate with an invocation list that concatenates the invocation lists of the delegates in the array. Returns null if is null, if contains zero elements, or if every entry in is null.

  The array of delegates to combine. 0
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Delegate `` ``

  and are not and not of the same 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. For example, suppose that a class named Derived is derived from a class named Base. 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 in Generics, but the two delegates cannot be combined because the types do not match exactly.

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

  Concatenates the invocation lists of two delegates.

  A new delegate with an invocation list that concatenates the invocation lists of and in that order. Returns if is null, returns if is a null reference, and returns a null reference if both and are null references.

  The delegate whose invocation list comes first. The delegate whose invocation list comes last. 0
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Delegate ``

  This method applies only if the current delegate is multicast (combinable).

  The current implementation simply throws a .

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

  Concatenates the invocation lists of the specified multicast (combinable) delegate and the current multicast (combinable) delegate.

  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 , or the current multicast (combinable) delegate if is null.

  The multicast (combinable) delegate whose invocation list to append to the end of the invocation list of the current multicast (combinable) delegate.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Delegate `` `` or is .

  does not derive from .

  -or-

  does not reflect a static method.

  The method of the delegate was not found.

  The caller does not have the required permission.

  Requires permission to access type information. See

  The method of the delegate was not found.

  In the .NET Framework version 1.0 and 1.1, this method overload creates delegates for static methods only. In the .NET Framework version 2.0, this method overload also can create open instance method delegates; that is, delegates that explicitly supply the hidden first argument of instance methods. For a detailed explanation, see the more general method overload, which allows you to create all combinations of open or closed delegates for instance or static methods, and optionally to specify a first argument.

  This method overload should be used when the delegate is not closed over its first argument, because it is somewhat faster in that case.

  This method overload is equivalent to calling the method overload and specifying true for .

  Starting with the net_v20sp1_long, this method can be used to access non-public methods if the caller has been granted with the flag and if the grant set of the non-public methods is restricted to the caller’s grant set, or a subset thereof. (See Security Considerations for Reflection.)

  To use this functionality, your application should target the net_v35_long or later.

  ## Compatible Parameter Types and Return Type

  In the .NET Framework version 2.0, the parameter types and return type of a delegate created using this method overload must be compatible with the parameter types and return type of the method the delegate represents; the types do not have to match exactly. This represents a relaxation of the binding behavior in the .NET Framework version 1.0 and 1.1, where the types must match exactly.

  A parameter of a delegate is compatible with the corresponding parameter of a method if the type of the delegate parameter is more restrictive than the type of the method parameter, because this guarantees that an argument passed to the delegate can be passed safely to the method.

  Similarly, the return type of a delegate is compatible with the return type of a method if the return type of the method is more restrictive than the return type of the delegate, because this guarantees that the return value of the method can be cast safely to the return type of the delegate.

  For example, a delegate with a parameter of type and a return type of can represent a method with a parameter of type and a return value of type .

  Creates a delegate of the specified type to represent the specified static method.

  A delegate of the specified type to represent the specified static method.

  The of delegate to create. The describing the static or instance method the delegate is to represent. Only static methods are supported in the .NET Framework version 1.0 and 1.1. 1 Reflection
- Method
  2.0.0.0
  4.0.0.0
  System.Delegate `` `` ``

  Calling this method overload is equivalent to calling the method overload and specifying true for . These two overloads provide the most flexible way to create delegates. You can use them to create delegates for either static or instance methods, and optionally to specify the first argument.

  If you do not supply a first argument, use the method overload for better performance.

  The delegate type and the method must have compatible return types. That is, the return type of must be assignable to the return type of .

  If is supplied, it is passed to every time the delegate is invoked; is said to be bound to the delegate, and the delegate is said to be closed over its first argument. If is static (Shared in Visual Basic), the argument list supplied when invoking the delegate includes all parameters except the first; if is an instance method, then is passed to the hidden instance parameter (represented by this in C#, or by Me in Visual Basic).

  If is supplied, the first parameter of must be a reference type, and must be compatible with that type.

  If is static (Shared in Visual Basic) and its first parameter is of type or , then can be a value type. In this case is automatically boxed. Automatic boxing does not occur for any other arguments, as it would in a C# or Visual Basic function call.

  If is a null reference and is an instance method, the result depends on the signatures of the delegate type and of :

  If the signature of explicitly includes the hidden first parameter of , the delegate is said to represent an open instance method. When the delegate is invoked, the first argument in the argument list is passed to the hidden instance parameter of .

  If the signatures of and match (that is, all parameter types are compatible), then the delegate is said to be closed over a null reference. Invoking the delegate is like calling an instance method on a null instance, which is not a particularly useful thing to do.

  If is a null reference and is static, the result depends on the signatures of the delegate type and of :

  If the signature of and match (that is, all parameter types are compatible), the delegate is said to represent an open static method. This is the most common case for static methods. In this case, you can get slightly better performance by using the method overload.

  If the signature of begins with the second parameter of and the rest of the parameter types are compatible, then the delegate is said to be closed over a null reference. When the delegate is invoked, a null reference is passed to the first parameter of .

  Starting with the net_v20sp1_long, this method can be used to access non-public methods if the caller has been granted with the flag and if the grant set of the non-public methods is restricted to the caller’s grant set, or a subset thereof. (See Security Considerations for Reflection.)

  To use this functionality, your application should target the net_v35_long or later.

  ## Compatible Parameter Types and Return Type

  The parameter types and return type of a delegate must be compatible with the parameter types and return type of the method the delegate represents; the types do not have to match exactly.

  In the .NET Framework version 1.0 and 1.1, the types must match exactly.

  A parameter of a delegate is compatible with the corresponding parameter of a method if the type of the delegate parameter is more restrictive than the type of the method parameter, because this guarantees that an argument passed to the delegate can be passed safely to the method.

  Similarly, the return type of a delegate is compatible with the return type of a method if the return type of the method is more restrictive than the return type of the delegate, because this guarantees that the return value of the method can be cast safely to the return type of the delegate.

  For example, a delegate with a parameter of type and a return type of can represent a method with a parameter of type and a return value of type .

  ## Determining the Methods a Delegate Can Represent

  Another useful way to think of the flexibility provided by this overload of is that any given delegate can represent four different combinations of method signature and method kind (static versus instance). Consider a delegate type D with one argument of type C. The following describes the methods D can represent, ignoring the return type since it must match in all cases:

  D can represent any instance method that has exactly one argument of type C, regardless of what type the instance method belongs to. When is called, is an instance of the type belongs to, and the resulting delegate is said to be closed over that instance. (Trivially, D can also be closed over a null reference if is a null reference.)

  D can represent an instance method of C that has no arguments. When is called, is a null reference. The resulting delegate represents an open instance method, and an instance of C must be supplied each time it is invoked.

  D can represent a static method that takes one argument of type C, and that method can belong to any type. When is called, is a null reference. The resulting delegate represents an open static method, and an instance of C must be supplied each time it is invoked.

  D can represent a static method that belongs to type F and has two arguments, of type F and type C. When is called, is an instance of F. The resulting delegate represents a static method that is closed over that instance of F. Note that in the case where F and C are the same type, the static method has two arguments of that type. (In this case, D is closed over a null reference if is a null reference.)

  Creates a delegate of the specified type that represents the specified static or instance method, with the specified first argument.

  A delegate of the specified type that represents the specified static or instance method.

  The of delegate to create. The object to which the delegate is bound, or null to treat as static (Shared in Visual Basic). The describing the static or instance method the delegate is to represent.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Delegate `` `` ``

  is .

  does not derive from .

  -or-

  is not an instance method.

  -or-

  does not implement .

  The caller does not have the required permission.

  Requires permission to access type information. See

  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.

  This method overload is equivalent to calling the method overload, specifying false for and true for .

  Starting with the net_v20sp1_long, this method can be used to access non-public methods if the caller has been granted with the flag and if the grant set of the non-public methods is restricted to the caller’s grant set, or a subset thereof. (See Security Considerations for Reflection.)

  To use this functionality, your application should target the net_v35_long or later.

  Creates a delegate of the specified type that represents the specified instance method to invoke on the specified class instance.

  A delegate of the specified type that represents the specified instance method to invoke on the specified class instance.

  The of delegate to create. The class instance on which is invoked. The name of the instance method that the delegate is to represent. 1 Reflection
- Method
  2.0.0.0
  4.0.0.0
  System.Delegate `` `` ``

  This method overload can create open static method delegates and open instance method delegates — that is, delegates that expose the hidden first argument of instance methods. For a detailed explanation, see the more general method overload, which allows you to create all combinations of open or closed delegates for instance or static methods.

  This method overload should be used when the delegate is not closed over its first argument, because it is somewhat faster in that case.

  Starting with the net_v20sp1_long, this method can be used to access non-public methods if the caller has been granted with the flag and if the grant set of the non-public methods is restricted to the caller’s grant set, or a subset thereof. (See Security Considerations for Reflection.)

  To use this functionality, your application should target the net_v35_long or later.

  ## Compatible Parameter Types and Return Type

  The parameter types and return type of a delegate must be compatible with the parameter types and return type of the method the delegate represents; the types do not have to match exactly.

  In the .NET Framework version 1.0 and 1.1, the types must match exactly.

  A parameter of a delegate is compatible with the corresponding parameter of a method if the type of the delegate parameter is more restrictive than the type of the method parameter, because this guarantees that an argument passed to the delegate can be passed safely to the method.

  Similarly, the return type of a delegate is compatible with the return type of a method if the return type of the method is more restrictive than the return type of the delegate, because this guarantees that the return value of the method can be cast safely to the return type of the delegate.

  For example, a delegate with a parameter of type and a return type of can represent a method with a parameter of type and a return value of type .

  Creates a delegate of the specified type to represent the specified static method, with the specified behavior on failure to bind.

  A delegate of the specified type to represent the specified static method.

  The of delegate to create. The describing the static or instance method the delegate is to represent. true to throw an exception if cannot be bound; otherwise, false.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Delegate `` `` ``

  is .

  does not derive from .

  -or-

  is not a static method.

  -or-

  does not implement .

  The caller does not have the required permission.

  Requires permission to access type information. See

  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.

  This method overload is equivalent to calling the method overload, specifying false for and true for .

  Starting with the net_v20sp1_long, this method can be used to access non-public methods if the caller has been granted with the flag and if the grant set of the non-public methods is restricted to the caller’s grant set, or a subset thereof. (See Security Considerations for Reflection.)

  To use this functionality, your application should target the net_v35_long or later.

  Creates a delegate of the specified type that represents the specified static method of the specified class.

  A delegate of the specified type that represents the specified static method of the specified class.

  The of delegate to create. The representing the class that implements . The name of the static method that the delegate is to represent. 1 Reflection
- Method
  2.0.0.0
  4.0.0.0
  System.Delegate `` `` `` ``

  This method overload and the method overload, which always throws on failure to bind, provide the most flexible way to create delegates. You can use them to create delegates for either static or instance methods, with or without a first argument.

  If you do not supply a first argument, use the method overload for better performance.

  The delegate type and the method must have compatible return types. That is, the return type of must be assignable to the return type of .

  If is supplied, it is passed to every time the delegate is invoked; is said to be bound to the delegate, and the delegate is said to be closed over its first argument. If is static (Shared in Visual Basic), the argument list supplied when invoking the delegate includes all parameters except the first; if is an instance method, then is passed to the hidden instance parameter (represented by this in C#, or by Me in Visual Basic).

  If is supplied, the first parameter of must be a reference type, and must be compatible with that type.

  If is static (Shared in Visual Basic) and its first parameter is of type or , then can be a value type. In this case is automatically boxed. Automatic boxing does not occur for any other arguments, as it would in a C# or Visual Basic function call.

  If is a null reference and is an instance method, the result depends on the signatures of the delegate type and of :

  If the signature of explicitly includes the hidden first parameter of , the delegate is said to represent an open instance method. When the delegate is invoked, the first argument in the argument list is passed to the hidden instance parameter of .

  If the signatures of and match (that is, all parameter types are compatible), then the delegate is said to be closed over a null reference. Invoking the delegate is like calling an instance method on a null instance, which is not a particularly useful thing to do.

  If is a null reference and is static, the result depends on the signatures of the delegate type and of :

  If the signature of and match (that is, all parameter types are compatible), the delegate is said to represent an open static method. This is the most common case for static methods. In this case, you can get slightly better performance by using the method overload.

  If the signature of begins with the second parameter of and the rest of the parameter types are compatible, then the delegate is said to be closed over a null reference. When the delegate is invoked, a null reference is passed to the first parameter of .

  Starting with the net_v20sp1_long, this method can be used to access non-public methods if the caller has been granted with the flag and if the grant set of the non-public methods is restricted to the caller’s grant set, or a subset thereof. (See Security Considerations for Reflection.)

  To use this functionality, your application should target the net_v35_long or later.

  ## Compatible Parameter Types and Return Type

  The parameter types and return type of a delegate must be compatible with the parameter types and return type of the method the delegate represents; the types do not have to match exactly.

  In the .NET Framework version 1.0 and 1.1 the types must match exactly.

  A parameter of a delegate is compatible with the corresponding parameter of a method if the type of the delegate parameter is more restrictive than the type of the method parameter, because this guarantees that an argument passed to the delegate can be passed safely to the method.

  Similarly, the return type of a delegate is compatible with the return type of a method if the return type of the method is more restrictive than the return type of the delegate, because this guarantees that the return value of the method can be cast safely to the return type of the delegate.

  For example, a delegate with a parameter of type and a return type of can represent a method with a parameter of type and a return value of type .

  ## Determining the Methods a Delegate Can Represent

  Another useful way to think of the flexibility provided by this overload of is that any given delegate can represent four different combinations of method signature and method kind (static versus instance). Consider a delegate type D with one argument of type C. The following describes the methods D can represent, ignoring the return type since it must match in all cases:

  D can represent any instance method that has exactly one argument of type C, regardless of what type the instance method belongs to. When is called, is an instance of the type belongs to, and the resulting delegate is said to be closed over that instance. (Trivially, D can also be closed over a null reference if is null.)

  D can represent an instance method of C that has no arguments. When is called, is a null reference. The resulting delegate represents an open instance method, and an instance of C must be supplied each time it is invoked.

  D can represent a static method that takes one argument of type C, and that method can belong to any type. When is called, is a null reference. The resulting delegate represents an open static method, and an instance of C must be supplied each time it is invoked.

  D can represent a static method that belongs to type F and has two arguments, of type F and type C. When is called, is an instance of F. The resulting delegate represents a static method that is closed over that instance of F. Note that in the case where F and C are the same type, the static method has two arguments of that type. (In this case, D is closed over a null reference if is null.)

  Creates a delegate of the specified type that represents the specified static or instance method, with the specified first argument and the specified behavior on failure to bind.

  A delegate of the specified type that represents the specified static or instance method, or null if is false and the delegate cannot be bound to .

  A representing the type of delegate to create. An that is the first argument of the method the delegate represents. For instance methods, it must be compatible with the instance type. The describing the static or instance method the delegate is to represent. true to throw an exception if cannot be bound; otherwise, false.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Delegate `` `` `` ``

  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.

  This method overload is equivalent to calling the method overload, specifying true for .

  Starting with the net_v20sp1_long, this method can be used to access non-public methods if the caller has been granted with the flag and if the grant set of the non-public methods is restricted to the caller’s grant set, or a subset thereof. (See Security Considerations for Reflection.)

  To use this functionality, your application should target the net_v35_long or later.

  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.

  A delegate of the specified type that represents the specified instance method to invoke on the specified class instance.

  The of delegate to create. The class instance on which is invoked. The name of the instance method that the delegate is to represent. A Boolean indicating whether to ignore the case when comparing the name of the method.
- Method
  2.0.0.0
  4.0.0.0
  System.Delegate `` `` `` ``

  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.

  This method overload is equivalent to calling the method overload, specifying true for .

  Starting with the net_v20sp1_long, this method can be used to access non-public methods if the caller has been granted with the flag and if the grant set of the non-public methods is restricted to the caller’s grant set, or a subset thereof. (See Security Considerations for Reflection.)

  To use this functionality, your application should target the net_v35_long or later.

  Creates a delegate of the specified type that represents the specified static method of the specified class, with the specified case-sensitivity.

  A delegate of the specified type that represents the specified static method of the specified class.

  The of delegate to create. The representing the class that implements . The name of the static method that the delegate is to represent. A Boolean indicating whether to ignore the case when comparing the name of the method.
- Method
  2.0.0.0
  4.0.0.0
  System.Delegate `` `` `` `` ``

  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.

  Starting with the net_v20sp1_long, this method can be used to access non-public methods if the caller has been granted with the flag and if the grant set of the non-public methods is restricted to the caller’s grant set, or a subset thereof. (See Security Considerations for Reflection.)

  To use this functionality, your application should target the net_v35_long or later.

  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 and the specified behavior on failure to bind.

  A delegate of the specified type that represents the specified instance method to invoke on the specified class instance.

  The of delegate to create. The class instance on which is invoked. The name of the instance method that the delegate is to represent. A Boolean indicating whether to ignore the case when comparing the name of the method. true to throw an exception if cannot be bound; otherwise, false.
- Method
  2.0.0.0
  4.0.0.0
  System.Delegate `` `` `` `` ``

  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.

  Starting with the net_v20sp1_long, this method can be used to access non-public methods if the caller has been granted with the flag and if the grant set of the non-public methods is restricted to the caller’s grant set, or a subset thereof. (See Security Considerations for Reflection.)

  To use this functionality, your application should target the net_v35_long or later.

  Creates a delegate of the specified type that represents the specified static method of the specified class, with the specified case-sensitivity and the specified behavior on failure to bind.

  A delegate of the specified type that represents the specified static method of the specified class.

  The of delegate to create. The representing the class that implements . The name of the static method that the delegate is to represent. A Boolean indicating whether to ignore the case when comparing the name of the method. true to throw an exception if cannot be bound; otherwise, false.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Object `System.ParamArray`

  The type of one or more elements in is invalid as a parameter to the methods implemented by the current instance.

  The caller does not have the required permissions.

  -or-

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

  A method in the invocation list of the current instance is an instance method and its target object is .

  -or-

  A method in the invocation list of the current instance was invoked on a target object or a class that does not implement it.

  The number of elements in is not equal to the number of parameters required by the methods invoked by the current instance.

  A method in the invocation list of the current instance threw an exception.

  This method calls the method.

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

  The object returned by the method represented by the delegate.

  An array of objects that are the arguments to pass to the method represented by the current delegate. 1 Reflection
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Object ``

  This method implements the method.

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

  The object returned by the method represented by the delegate.

  An array of objects that are the arguments to pass to the method represented by the current delegate.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Boolean ``

  If the two delegates are not of the same type, they are not considered equal.

  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.

  Determines whether the specified object and the current delegate are of the same type and share the same targets, methods, and invocation list.

  true if and the current delegate have the same targets, methods, and invocation list; otherwise, false.

  The object to compare with the current delegate. 0
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Int32

  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.

  Returns a hash code for the delegate.

  A hash code for the delegate.

  0
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Delegate[]

  Each delegate in the array represents exactly one method.

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

  Returns the invocation list of the delegate.

  An array of delegates representing the invocation list of the current delegate.

  0
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Reflection.MethodInfo

  This method applies only if the current delegate represents a static method.

  Gets the static method represented by the current delegate.

  A describing the static method represented by the current delegate.

- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Void `` `` To be added.

  Not supported.

  Not supported. Not supported.
- Property
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Reflection.MethodInfo

  A .

  This property is read-only.

  The caller does not have the required permissions. Requires permission to access type information. See .

  Gets the method represented by the delegate.

  1
  Reflection
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Boolean `` ``

  Two delegates of the same type with the same targets, methods, and invocation lists are considered equal.

  If the two delegates are not of the same type, they are not considered equal.

  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 if they have the same order and the corresponding elements from the two lists represent the same method and target.

  Determines whether the specified delegates are equal.

  true if is equal to ; otherwise, false.

  The first delegate to compare. The second delegate to compare. 0
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Boolean `` ``

  Two delegates are considered not equal if they are of different types, or have different methods, different targets, or different invocation lists.

  If the two delegates are not of the same type, they are not considered equal.

  In the .NET Framework version 1.0 and 1.1, two delegates are 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 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.

  Determines whether the specified delegates are not equal.

  true if is not equal to ; otherwise, false.

  The first delegate to compare. The second delegate to compare. 0
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Delegate `` ``

  The following example demonstrates the method.

  `using System; class MyClass { public string InstanceMethod(string s) { return ("Instance String " + s); } } class MyClass2 { public string InstanceMethod2(string s) { return ("Instance String2 " + s); } } public delegate string DelegatedMethod(string s); class TestClass { public static void WriteDelegate (string label, Delegate d) { Console.WriteLine("Invocation list targets for {0}:",label); foreach(Delegate x in d.GetInvocationList()) Console.WriteLine("{0}",x.Target); } public static void Main() { MyClass myInstance = new MyClass(); DelegatedMethod delInstance = new DelegatedMethod(myInstance.InstanceMethod); MyClass2 myInstance2 = new MyClass2(); DelegatedMethod delInstance2 = new DelegatedMethod(myInstance2.InstanceMethod2); DelegatedMethod [] sourceArray = {delInstance, delInstance2, delInstance2, delInstance}; DelegatedMethod [] remove1 = {delInstance}; DelegatedMethod [] remove2 = {delInstance2, delInstance2}; DelegatedMethod [] remove3 = {delInstance2, delInstance}; DelegatedMethod [] remove4 = {delInstance, delInstance2}; DelegatedMethod [] remove5 = {delInstance, delInstance}; Delegate source = Delegate.Combine(sourceArray); // Display invocation list of source TestClass.WriteDelegate("source", source); //Test 1: value occurs in source twice. Delegate value1 = Delegate.Combine(remove1); Delegate result1 = Delegate.Remove(source, value1); TestClass.WriteDelegate("value1", value1); if (result1==null) { Console.WriteLine("removal test 1 result is null"); } else { TestClass.WriteDelegate("result1", result1); } //Test 2: value matches the middle two elements of source. Delegate value2 = Delegate.Combine(remove2); Delegate result2 = Delegate.Remove(source, value2); TestClass.WriteDelegate("value2", value2); if (result2==null) { Console.WriteLine("removal test 2 result2 is null"); } else { TestClass.WriteDelegate("result2", result2); } //Test 3: value matches the last two elements of source. Delegate value3 = Delegate.Combine(remove3); Delegate result3 = Delegate.Remove(source, value3); TestClass.WriteDelegate("value3", value3); if (result3==null) { Console.WriteLine("removal test 3 result3 is null"); } else { TestClass.WriteDelegate("result3", result3); } //Test 4: value matches the first two elements of source. Delegate value4 = Delegate.Combine(remove4); Delegate result4 = Delegate.Remove(source, value4); TestClass.WriteDelegate("value4", value4); if (result4==null) { Console.WriteLine("removal test 4 result4 is null"); } else { TestClass.WriteDelegate("result4", result4); } //Test 5: value does not occur in source. Delegate value5 = Delegate.Combine(remove5); Delegate result5 = Delegate.Remove(source, value5); TestClass.WriteDelegate("value5", value5); if (result5==null) { Console.WriteLine("removal test 5 result5 is null"); } else { TestClass.WriteDelegate("result5", result5); } //Test 6: value exactly matches source. Delegate result6 = Delegate.Remove(source, source); TestClass.WriteDelegate("value=source", source); if (result6==null) { Console.WriteLine("removal test 6 result6 is null"); } else { TestClass.WriteDelegate("result6", result6); } } }`

  The output is

  Invocation list targets for source:

  MyClass

  MyClass2

  MyClass2

  MyClass

  Invocation list targets for value1:

  MyClass

  Invocation list targets for result1:

  MyClass

  MyClass2

  MyClass2

  Invocation list targets for value2:

  MyClass2

  MyClass2

  Invocation list targets for result2:

  MyClass

  MyClass

  Invocation list targets for value3:

  MyClass2

  MyClass

  Invocation list targets for result3:

  MyClass

  MyClass2

  Invocation list targets for value4:

  MyClass

  MyClass2

  Invocation list targets for result4:

  MyClass2

  MyClass

  Invocation list targets for value5:

  MyClass

  MyClass

  Invocation list targets for result5:

  MyClass

  MyClass2

  MyClass2

  MyClass

  Invocation list targets for value=source:

  MyClass

  MyClass2

  MyClass2

  MyClass

  removal test 6 result6 is null

  If the invocation list of matches a contiguous set of elements in the invocation list of , then the invocation list of is said to occur within the invocation list of . If the invocation list of occurs more than once in the invocation list of , the last occurrence is removed.

  Removes the last occurrence of the invocation list of a delegate from the invocation list of another delegate.

  A new delegate with an invocation list formed by taking the invocation list of and removing the last occurrence of the invocation list of , if the invocation list of is found within the invocation list of . Returns if is null or if the invocation list of is not found within the invocation list of . Returns a null reference if the invocation list of is equal to the invocation list of or if is a null reference.

  The delegate from which to remove the invocation list of . The delegate that supplies the invocation list to remove from the invocation list of . 0
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Delegate `` ``

  If the invocation list of matches a contiguous set of elements in the invocation list of , then the invocation list of is said to occur within the invocation list of . If the invocation list of occurs more than once in the invocation list of , all occurrences are removed.

  Removes all occurrences of the invocation list of a delegate from the invocation list of another delegate.

  A new delegate with an invocation list formed by taking the invocation list of and removing all occurrences of the invocation list of , if the invocation list of is found within the invocation list of . Returns if is null or if the invocation list of is not found within the invocation list of . Returns a null reference if the invocation list of is equal to the invocation list of , if contains only a series of invocation lists that are equal to the invocation list of , or if is a null reference.

  The delegate from which to remove the invocation list of . The delegate that supplies the invocation list to remove from the invocation list of . 0
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Delegate ``

  If the invocation list of matches a contiguous set of elements in the current delegate's invocation list, then the invocation list of is said to occur within the current delegate's invocation list. If the invocation list of occurs more than once in the current delegate's invocation list, the last occurrence is removed.

  Removes the invocation list of a delegate from the invocation list of another delegate.

  A new delegate with an invocation list formed by taking the invocation list of the current delegate and removing the invocation list of , if the invocation list of is found within the current delegate's invocation list. Returns the current delegate if is null or if the invocation list of is not found within the current delegate's invocation list. Returns null if the invocation list of is equal to the current delegate's invocation list.

  The delegate that supplies the invocation list to remove from the invocation list of the current delegate.
- Property
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Object

  A instance, or if the delegate invokes only static methods.

  Example 1:

  The following example gets the property values for two delegates. The first delegate invokes a static method, and the second invokes an instance method.

  `using System; public delegate string DelegatedMethod(string s); class MyClass { public static string StaticMethod(string s) { return ("Static method Arg=" + s); } public string InstanceMethod(string s) { return ("Instance method Arg=" + s); } } class TestClass { public static void Main() { MyClass myInstance = new MyClass(); //Create delegates from delegate type DelegatedMethod. DelegatedMethod delStatic = new DelegatedMethod(MyClass.StaticMethod); DelegatedMethod delInstance = new DelegatedMethod(myInstance.InstanceMethod); object t = delStatic.Target; Console.WriteLine ("Static target is {0}", t==null ? "null":t); t = delInstance.Target; Console.WriteLine ("Instance target is {0}", t==null ? "null":t); } }`

  The output is

  Static target is null

  Instance target is MyClass

  Example 2:

  The following example gets the property value for three delegates created using instance methods, static methods, and a combination of the two.

  `using System; class MyClass { public static string StaticMethod(string s) { return ("Static String " + s); } public string InstanceMethod(string s) { return ("Instance String " + s); } } class MyClass2 { public static string StaticMethod2(string s) { return ("Static String2 " + s); } public string InstanceMethod2(string s) { return ("Instance String2 " + s); } } public delegate string DelegatedMethod(string s); class TestClass { public static void Main() { DelegatedMethod delStatic = new DelegatedMethod(MyClass.StaticMethod); DelegatedMethod delStatic2 = new DelegatedMethod(MyClass2.StaticMethod2); MyClass myInstance = new MyClass(); DelegatedMethod delInstance = new DelegatedMethod(myInstance.InstanceMethod); MyClass2 myInstance2 = new MyClass2(); DelegatedMethod delInstance2 = new DelegatedMethod(myInstance2.InstanceMethod2); Delegate d = Delegate.Combine(delStatic, delInstance ); Delegate e = Delegate.Combine(delInstance,delInstance2); Delegate f = Delegate.Combine(delStatic, delStatic2 ); if (d!=null) { Console.WriteLine("Combined 1 static, 1 instance, same class:"); Console.WriteLine("target...{0}", d.Target == null ? "null" : d.Target); foreach(Delegate x in d.GetInvocationList()) Console.WriteLine("invoke element target: {0}",x.Target); } Console.WriteLine(""); if (e!=null) { Console.WriteLine("Combined 2 instance methods, different classes:"); Console.WriteLine("target...{0}", e.Target == null ? "null" : e.Target); foreach(Delegate x in e.GetInvocationList()) Console.WriteLine("invoke element target: {0}",x.Target); } Console.WriteLine(""); if (f!=null) { Console.WriteLine("Combined 2 static methods, different classes:"); Console.WriteLine("target...{0}", f.Target == null ? "null" : f.Target); foreach(Delegate x in f.GetInvocationList()) Console.WriteLine("invoke element target: {0}",x.Target); } } }`

  The output is

  Combined 1 static, 1 instance, same class:

  target...MyClass

  invoke element target:

  invoke element target: MyClass

  Combined 2 instance methods, different classes:

  target...MyClass2

  invoke element target: MyClass

  invoke element target: MyClass2

  Combined 2 static methods, different classes:

  target...null

  invoke element target:

  invoke element target:

  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.

  Gets the class instance on which the current delegate invokes the instance method.

  0
0