I've seen some coders on pluralsight cast their EventHandler to a delegate before executing. Why is this a good practice? Usually I just invoke the event without casting.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication13
{
public class Mediator
{
public event EventHandler<EmployeeArgs> EmployeeEventChange;
private static readonly Mediator _Instance = new Mediator();
private Mediator() { }
public static Mediator GetInstance()
{
return _Instance;
}
public void OnEmployeeHandler(Employee e)
{
var EmployeeEventDelegate = EmployeeEventChange as EventHandler<EmployeeArgs>;
if (EmployeeEventDelegate != null)
{
EmployeeEventDelegate(this, new EmployeeArgs()
{
Employee = e
});
}
}
}
}