// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; namespace E { public class P { public delegate void D(object sender, EventArgs args); public event D Test; public void TestTest() { Test(this, null); } } public class C { public delegate void D(object sender, EventArgs args); public event D Test { add { Console.WriteLine("Adding"); Test += value; } remove { Console.WriteLine("Removing"); Test -= value; } } public void TestTest() { Test(this, null); } } public class Program { public static void TestD(object sender, EventArgs args) { Console.WriteLine("TestD called"); } public static void Main(string[] args) { P p = new P(); p.Test += TestD; p.TestTest(); C c = new C(); c.Test += TestD; c.TestTest(); Console.ReadKey(); } } }