Edit

Share via


Delegate Constructors

Definition

Initializes a new delegate.

Overloads

Delegate(Object, String)

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

Delegate(Type, String)

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

Delegate(Object, String)

Source:
Delegate.CoreCLR.cs
Source:
Delegate.CoreCLR.cs
Source:
Delegate.CoreCLR.cs

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

protected:
 Delegate(System::Object ^ target, System::String ^ method);
protected Delegate (object target, string method);
new Delegate : obj * string -> Delegate
Protected Sub New (target As Object, method As String)

Parameters

target
Object

The class instance on which the delegate invokes method.

method
String

The name of the instance method that the delegate represents.

Exceptions

target is null.

-or-

method is null.

There was an error binding to the target method.

Remarks

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 CreateDelegate method that specifies a method name and a target object. For example, the CreateDelegate(Type, Object, String) 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.

See also

Applies to

Delegate(Type, String)

Source:
Delegate.CoreCLR.cs
Source:
Delegate.CoreCLR.cs
Source:
Delegate.CoreCLR.cs

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

protected:
 Delegate(Type ^ target, System::String ^ method);
protected Delegate (Type target, string method);
new Delegate : Type * string -> Delegate
Protected Sub New (target As Type, method As String)

Parameters

target
Type

The Type representing the class that defines method.

method
String

The name of the static method that the delegate represents.

Exceptions

target is null.

-or-

method is null.

target is not a RuntimeType. See Runtime Types in Reflection).

-or-

target represents an open generic type.

Remarks

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 CreateDelegate method that specifies a method name but does not specify a target object. For example, the CreateDelegate(Type, Type, String) 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.

See also

Applies to