using System;
namespace NilPointer
{
class Program
{
public delegate void UpdateNameHandler(string name);
public class Employee
{
public event UpdateNameHandler nameHandler;
private string name;
public string Name
{
get
{
return name;
}
set
{
name = value;
if (nameHandler != null)
{
nameHandler(name);
}
}
}
}
private static void sendMail(string name)
{
Console.WriteLine("Send Email: " + name);
}
private static void writeLog(string name)
{
Console.WriteLine("Write Log: " + name);
}
static void Main(string[] args)
{
var employee = new Employee();
employee.nameHandler += writeLog;
employee.nameHandler += sendMail;
employee.Name = "Name 1";
employee.Name = "Name 2";
Console.ReadLine();
}
}
}
Write Log: Name 1
Send Email: Name 1
Write Log: Name 2
Send Email: Name 2