Delegate 建構函式

定義

初始化新的委派。

多載

Delegate(Object, String)

初始化委派,這個委派會在指定的類別執行個體上叫用指定的執行個體方法。

Delegate(Type, String)

初始化委派,這個委派會從指定的類別叫用指定的靜態方法。

Delegate(Object, String)

初始化委派,這個委派會在指定的類別執行個體上叫用指定的執行個體方法。

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)

參數

target
Object

委派用來叫用 method 的類別執行個體。

method
String

委派表示的執行個體方法名稱。

例外狀況

targetnull

-或- methodnull

繫結至目標方法時發生錯誤。

備註

這個函式不能用在應用程式程式碼中。 若要藉由指定實例方法的名稱來建立委派,請使用 CreateDelegate 指定方法名稱和目標物件之方法的多載。 例如,方法多載會 CreateDelegate(Type, Object, String) 建立具有指定名稱之實例方法的委派。

這個函式只會建立實例方法的委派。 實例方法是與類別實例相關聯的方法;靜態方法是與類別本身相關聯的方法。

另請參閱

適用於

Delegate(Type, String)

初始化委派,這個委派會從指定的類別叫用指定的靜態方法。

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)

參數

target
Type

Type,代表定義 method 的類別。

method
String

委派表示的靜態方法名稱。

例外狀況

targetnull

-或- methodnull

target 不是 RuntimeType。 請參閱 Runtime Types in Reflection

-或- target 代表開放式泛型類型。

備註

這個函式不能用在應用程式程式碼中。 若要藉由指定靜態方法的名稱來建立委派,請使用 CreateDelegate 指定方法名稱但未指定目標物件之方法的多載。 例如,方法多載會 CreateDelegate(Type, Type, String) 針對具有指定名稱的方法建立靜態委派。

這個函式只會建立靜態方法的委派。 實例方法是與類別實例相關聯的方法;靜態方法是與類別本身相關聯的方法。

另請參閱

適用於