Things that annoy me about C# - delegates
Me and a colleague have been discussing things wrong with C#. Delegates somehow seem like a broken design. For instance, when I start a new thread, why do I need to pass an instance of the ThreadStart delegate? Why not just pass the method?
For instance, instead of:
Thread t = new Thread(new ThreadStart(SomeMethod)); t.Start();How about:
Thread t = new Thread(SomeMethod); t.Start();Much cleaner. On a similar theme, why not allow a method to implicitly declare a delegate, so instead of:
SomeDelegate dele = new SomeDelegate(this.SomeMethod); dele.BeginInvoke(null, null);How about:
this.SomeMethod.BeginInvoke(null, null);Also, delegates are not interchangeable. If you declare two delegates with the same signature, they cannot be used interchangeably, why not? Delegates and System.Reflection.MethodInfo seem very similar, they "smell" in refactoring terms, begging to be combined in some way...

0 Comments:
Post a Comment
<< Home