Delegate Constructors
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Initializes a new delegate.
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. |
- 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
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 |
- 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
- method
- String
The name of the static method that the delegate represents.
Exceptions
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 |