<T> action against delegation
I saw developers using the codes below as an alternative. What is the difference between them and which ones go by standard? Are they the same as Action and Func<T> also a delegate:
public event Action<EmployeeEventAgs> OnLeave; public void Leave() { OnLeave(new EmployeeEventAgs(this.ID)); } VS
public delegate void GoOnLeave(EmployeeEventAgs e); public event GoOnLeave OnLeave; public void Leave() { OnLeave(new EmployeeEventAgs(this.ID)); } Fwiw, no example uses standard .NET conventions. The EventHandler<T> generator should declare an event:
public event EventHandler<EmployeeEventArgs> Leave; The prefix "On" must be reserved for the protected method that raises the event:
protected virtual void OnLeave(EmployeeEventArgs e) { var handler = Leave; if (handler != null) handler(this, e); } You do not have to do this, but someone will instantly recognize the template, understand your code and know how to use and configure it.
And this has the big advantage that you should not choose between a custom delegate declaration and Action<> , EventHandler<> is the best way. Which answers your question.

Action<T> exactly the same as delegate void ... (T t)
Func<T> exactly matches delegate T ... ()
The following two lines of code are almost equivalent:
public event Action<EmployeeEventAgs> Leave; Unlike:
public event EventHandler<EmployeeEventAgs> Leave; The difference lies in the signature of the event handler method. If you are using the first approach to action, you can:
public void LeaveHandler(EmployeeEventAgs e) { ... } and then this:
obj.Leave += LeaveHandler; In the second approach, the LeaveHandler signature should be different:
public void LeaveHandler(object sender, EmployeeEventAgs e) { ... } It is very important to note that in both cases the keyword event present. An event declared explicitly as such using the keyword event is no longer a class field. Instead, it becomes an event . Event properties are similar to regular properties, except that they do not have get or set accessories. The compiler allows you to use them only on the left side of the assignments += and -= (add or remove an event handler). It is not possible to overwrite already assigned event handlers or raise an event outside the class declaring it.
If the event keyword is missing in both examples, you can perform the following operations without errors or warnings:
obj.Leave = LeaveHandler; which will remove any registered handlers and replace them with a LeaveHandler .
Alternatively, you can also make this call:
obj.Leave(new EmployeeEventAgs()); The two examples above are considered an anti-pattern if you intend to create an event. The event should be triggered only by the owner object and should not allow dispassionate deletion of subscribers. The event keyword is a .NET programming construct that helps you use events correctly.
Based on the foregoing, I believe that many adhere to the EventHandler approach, because it is unlikely to use an EventHandler without the event keyword. Actions have a wider range of uses; they do not look natural when used as events. The latter, of course, is a personal opinion, since the approach of the event handler has probably changed too much in my coding methods. However, if the actions are used correctly, it is not a crime to use them for events.
An action is just a shortcut to the full declaration of a delegate.
public delegate void Action<T>(T obj) http://msdn.microsoft.com/en-us/library/018hxwa8.aspx
Which one will depend on the standards / coding style of your organization.
Yes, Action and Func are just convenient delegates that were defined in 3.5 clr.
Action, Func and lambdas are just syntactic sugar and usability for delegates.
There is nothing magical about them. Several people have written simple 2.0 add-on libraries to add this functionality to 2.0 code.
You might want to look here that the best that the compiler generates for Action is the best description. There is no functional difference in what you wrote, just a shorter, more convenient syntax.
In general, they are equivalent. But in the context of using a delegate for an event type, the convention should use an EventHandler (where T inherits EventArgs):
public event EventHandler<EmployeeEventArgs> Left; public void Leave() { OnLeft(this.ID); } protected virtual void OnLeft(int id) { if (Left != null) { Left(new EmployeeEventArgs(id)); } } You could write these common Action and Func delegates yourself, but since they are generally useful, they wrote them for you and are stuck in .Net libraries.