Skip to content

The Hard Way

June 20, 2008

I work with people who like to type.

ddlSystemType.SelectedIndex = ddlSystemType.Items.IndexOf(ddlSystemType.Items.FindByValue(sdr[“systype_id”].ToString().Trim()));

Easier:

ddlSystemType.SelectedValue = result.systype_id == null ? “-1” : result.systype_id;

But wait.  I can beat that.  I unaccountably only recently learned about the null coalescing operator.  We could have used:

ddlSystemType.SelectedValue = result.systype_id ?? “-1”;

Briefly, if the value on the left is null, use the value on the right, if the value is not null, use the value.

PS.  After you’ve been coding for hours and hours and switch to writing blog posts or emails in English do you end your sentences with semicolons instead of periods?  I do. =oP

Advertisements
No comments yet

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: