delegate 與 event 的關係
delegate僅僅是回調函數嗎?
event在。net中主要用在什麼地方?
- Event handlers (for GUI and more)
- Starting threads
- Callbacks (e.g. for async APIs)
- LINQ and similar (List.Find etc)
- Anywhere else where I want to effectively apply "template" code with some specialized logic inside (where the delegate provides the specialization)
type-safe
參數的類型,返回值的類型
Demystifying
a constructor
Invoke
BeginInvoke
EndInvoke
_target
_methodPtr
_invocationList
-------------------------------
Chaining
+=
-=
Generic Delegates
public delegate void Action<T> (T obj);
public delegate TResult Func<TResult>();
delegate void EventHandler<TEventArgs> (Object sender, TEventArgs e) where TEventArgs : EventArgs;
Syntactical Sugar