event注意事项:
1.只能使用+=或者-=。
2.加不加对代码没有影响
示例1:
public event Action ac;
public void Start(Action action, int time)
{
while (true)
{
action();
System.Threading.Thread.Sleep(time);
}
}
Mytime time = new Mytime();
time.Start(() =>
{
Console.WriteLine("伍总");
}, 1000);
示例2:
public event Action ac;
public void Start(int time)
{
while (true)
{
ac();
System.Threading.Thread.Sleep(time);
}
}
static void Main()
{
Mytime time = new Mytime();
time.ac += time_ac;
time.ac += time_ac2;
time.Start(1000);
}
static void time_ac()
{
Console.WriteLine("伍总");
}
static void time_ac2()
{
Console.WriteLine("伍总");
}