Working with delegates and events

Here are some built-in handlers for the .Net Framework:

EventHandler // Default event callbacks
EventHandler<T> // Default event callbacks with custom parameter (inheriting from EventArgs)
Action // Function without return value and without parameter
Action<T1, T2, T3, T4> // Function without return value and 1-4 parameters
Func<T1, T2, T3, T4, TResult> // Methos with 0-4 parameters and one result type

Predicate<T> // equivalent to Func<T, bool>
Comparison<T> // equivalent to Func<T1, T2, int>

example: using delegates with events

public delegate void ModelChangedHandler(object sender, int row);
public event ModelChangedHandler ModelChanged;

void notifyupdatemodel()
    if (ModelChanged != null)
        ModelChanged(this, rownum);

Pointing out replacement/default actions/funcs:

private Action<int> shoot;
is equivalent to:
public delegate void ShootingHandler(int times);
private ShootingHandler shoot;

What's your thoughts on this?


Protected by WP Anti Spam