【发布时间】:2016-04-24 20:24:07
【问题描述】:
考虑以下来自dotnetperls 的示例:
using System;
public delegate void EventHandler();
class Program
{
public static event EventHandler _show;
static void Main()
{
// Add event handlers to Show event.
_show += new EventHandler(Dog);
_show += new EventHandler(Cat);
_show += new EventHandler(Mouse);
_show += new EventHandler(Mouse);
// Invoke the event.
_show.Invoke();
}
static void Cat()
{
Console.WriteLine("Cat");
}
static void Dog()
{
Console.WriteLine("Dog");
}
static void Mouse()
{
Console.WriteLine("Mouse");
}
}
使用静态修饰符有什么意义?
【问题讨论】:
-
因为你从静态方法中使用它 - static void Main()
标签: c# eventhandler