Home > View Post

Write a tiny bit less code

... with these low budget tips.


string[] names = new string[2];
names[0] = "barry";
names[1] = "john";

Everybody knows you can do that. Most people also know you can do this instead:

string[] names = new string[] {"barry", "john"};

But did you know you can get away with as little as this?

string[] names = {"barry", "john"};


Wiring up delegates is cumbersome...

ThreadPool.QueueUserItem(new WaitCallBack(MyMethod), null)


_btn.OnClick += new EventHandler(_btn_Onclick);

However, you don't need to new up the delegate if you're feeling lazy, e.g.

ThreadPool.QueueUserItem(MyMethod, null)
_btn.OnClick += _btn_Onclick;

Better eh? Well shorter, think of all the keypresses we've just saved.

Coming soon

More low budget tips from thejoyofcode.com :)

Tags: C#

Josh Post By Josh Twist
8:43 AM
08 Feb 2007

» Next Post: Keyboard shortcuts
« Previous Post: Are you tester using TFS to track bugs for a Web Application

Comments are closed for this post.

© 2005 - 2022 Josh Twist - All Rights Reserved.