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 (object target, string method);

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

.NET 9 及其他版本
產品 版本
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

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, string method);

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

.NET 9 及其他版本
產品 版本
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1