13 Şubat 2018 Salı

Delegate Sınıfı

Giriş
Şu satırı dahil ederiz.
using Sytem.Delegate;
Soyut bir sınıftır. Açıklaması şöyle.
The Delegate class is the base class for delegate types. However, only the system and compilers can derive explicitly from the Delegate class or from the MulticastDelegate class. It is also not permissible to derive a new type from a delegate type. The Delegate 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 MulticastDelegate class; therefore, users should use the delegate keyword provided by the language.
CreateDelegate metodu
Şöyle yaparız.
MethodInfo method = ...;
var action = (Action<Handler, int>) 
    Delegate.CreateDelegate(typeof(Action<Handler, int>), method);
Combine metodu
İmzası şöyle
public static Delegate Combine(Delegate a, Delegate b);

Hiç yorum yok:

Yorum Gönder