A Little C# 2.0 Gem
You may already know this (maybe I did at one point, but if so I surely forgot it), but I learned it today and was pleasantly surprised (I'm easily impressed). I would like to thank ReSharper for this discovery <g>!
Anyways, here it is. If you're using anonymous methods on a defined delegate type and your method body is not using any of the parameters for the delegate signature, you can simply omit the entire parameters section. Here's an example.
1: Timer t = new Timer(2000);
2: t.AutoReset = false;
3: t.Enabled = true;
4: t.Elapsed += new ElapsedEventHandler(delegate { 5: bugFlowSvc.CloseBug(instance.InstanceId, bug);
6: });
I'm so easily amused!
Comment Notification
If you would like to receive an email when updates are made to this post, please register here
Subscribe to this post's comments using
Comments
Leave a Comment
About hdierking
I am currently the Editor-in-Chief for MSDN Magazine. I joined Microsoft in 2006 as a product planner with the certification team at Microsoft Learning. Prior to that, I spent my career as a developer and later as an architect. My main technology passions include pretty much anything on language theory, agile development, and service-oriented architecture.