Skip Navigation LinksHome > View Post
Write a tiny bit less code

... with these low budget tips.

Arrays

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"};

Delegates

Wiring up delegates is cumbersome...

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

Or

_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
08:43
08 Feb 2007

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

Comments:

Post a comment:

Name  

E-mail (never shared)

URL

Comments  

Captcha ImageRefresh Image
What's this?
Enter code above