110,533
社区成员
发帖
与我相关
我的任务
分享
using System;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
var shape = new Rectangle();
shape.Hi += new EventHandler<EventArgs>(shape_Hi);
shape.Alert();
shape = new Rectangle();
shape.Hi += new EventHandler<EventArgs>(Other.Other_Hi);
shape.Alert();
}
static void shape_Hi(object sender, EventArgs e)
{
Console.WriteLine("Shape_Hi");
}
}
public class Shape
{
public event EventHandler<EventArgs> Hi;
public void Alert()
{
if (this.Hi != null)
Hi(this, EventArgs.Empty);
}
}
public class Rectangle : Shape
{
}
public class Circle : Shape
{
}
public class Other
{
public static void Other_Hi(object sender, EventArgs e)
{
Console.WriteLine("Other_Hi");
}
}
}