From: Tony Johansson on 16 Mar 2010 16:11 Hi! Here is a simple example on an anonymous method that works test.myEvent += delegate(object sender, EventArgs e) { Console.WriteLine("Test"); }; How do I write the anonymous method within the EventHandler I have tried here but this gives compile error test.myEvent +=new EventHandler(Console.WriteLine("Test");); //Tony
From: Family Tree Mike on 16 Mar 2010 16:33 On 3/16/2010 4:11 PM, Tony Johansson wrote: > Hi! > > Here is a simple example on an anonymous method that works > test.myEvent += delegate(object sender, EventArgs e) > { > Console.WriteLine("Test"); > }; > > How do I write the anonymous method within the EventHandler I have tried > here but this gives compile error > test.myEvent +=new EventHandler(Console.WriteLine("Test");); > > //Tony > > I prefer your first example, but if you want, you could do this: test.myEvent += new EventHandler(delegate {Console.WriteLine("Test");}); -- Mike
From: Tom Shelton on 16 Mar 2010 18:07 On 2010-03-16, Family Tree Mike <FamilyTreeMike(a)ThisOldHouse.com> wrote: > On 3/16/2010 4:11 PM, Tony Johansson wrote: >> Hi! >> >> Here is a simple example on an anonymous method that works >> test.myEvent += delegate(object sender, EventArgs e) >> { >> Console.WriteLine("Test"); >> }; >> >> How do I write the anonymous method within the EventHandler I have tried >> here but this gives compile error >> test.myEvent +=new EventHandler(Console.WriteLine("Test");); >> >> //Tony >> >> > > I prefer your first example, but if you want, you could do this: > > test.myEvent += new > EventHandler(delegate {Console.WriteLine("Test");}); > > You don't even have to do that in 2008: test.myEvent += (o, ea) => Console.WriteLine("Test"); -- Tom Shelton
|
Pages: 1 Prev: IIS Application Pools Next: Send form windows to the back of -global- Z-order |