delegate void del(); class MyClass1 { public event del eventcount;//创建事件并发布 public void Count() { for (int i = 0; i < 100; i++) { if (i % 12 == 0 && eventcount != null) { eventcount(); } } } } class MyClass2 { public int sum { get; set; } public MyClass2(MyClass1 myClass1) { sum = 0; myClass1.eventcount += sumj;//订阅事件 } void sumj() { sum++; } } class Program { static void Main(string[] args) { MyClass1 myClass1 = new MyClass1(); MyClass2 myClass2 = new MyClass2(myClass1); myClass1.Count(); Console.WriteLine(myClass2.sum); } }