i created a class and when i create an employee object via form , i want to give a message;
this is my class, event and delegate
public delegate void cto
By the time you subscribe for this event the instance is already constructed. I would recommend using Factory pattern to hide the constructor.
class EmployeeFactory
{
public Employee Create(int id, string name)
{
Employee instance = new Employee(id, name);
var handler = EmployeeCreated;
if (handler != null)
{
EmployeeEventArgs e = new EmployeeEventArgs(instance);
handler(e);
}
return instance;
}
public event EventHandler EmployeeCreated;
}
Event subscription:
factory.EmployeeCreated += MyHandler;
Instance construction:
var emp = factory.Create(id, name);