<October 2020>

On this page...



Member of...

ASP Insiders

MVP Visual Developer ASP/ASP.NET

Enter CodeZone

Blog Categories



Deutsche Resourcen


Sign In

#  Wednesday, November 8, 2006

From the nuggets page: Don't have the time to read a 10-page how-to article or watch a full length webcast? Try an MSDN Nugget, a webcast that takes you step-by-step to discovering new functionality or exploring a hot developer topic, all in 10-15 minutes. If you haven't seen this yet, check it out!

Categories: .NET | ASP.NET | BCL | Training and Conferences
Wednesday, November 8, 2006 3:04:26 PM (W. Europe Standard Time, UTC+01:00)  #    Comments [0]


#  Wednesday, March 9, 2005
A new Channel 9 wiki has popped up - about performance tips for managed code and related CLR "stuff". A really usefull collection of articles, videos et al - check it out!
Categories: .NET | BCL | C#
Wednesday, March 9, 2005 5:03:33 PM (W. Europe Standard Time, UTC+01:00)  #    Comments [0]


#  Tuesday, February 22, 2005

The BCL Team has an interesting blog post for all those of you who want to solve every string matching problem using a regular expression. Kit George reflects on when not to use RegEx to match strings.

Categories: .NET | BCL
Tuesday, February 22, 2005 2:12:03 AM (W. Europe Standard Time, UTC+01:00)  #    Comments [0]


#  Tuesday, July 27, 2004

Continuing in the “What’s cool in 2.0” series, I’ll look at a BCL feature today. Imagine you have a Web form, and one of the values a user has to enter is a double. The not-so-ingenious version to accomplish the task is as follows:

void Button1_Click(object sender, EventArgs e)
string val = TextBox1.Text;

// I'm sure: it is a double
double d = Double.Parse(val);

What’s wrong? Well, there are several things that could make your application go south, err, throw an exception: the value is null, the value is not a double, the value is out of range for a double (all three conditions are well-documented). So you rewrite your application like this:

double d = 0.0f;
d = Double.Parse(val);
catch (ArgumentNullException ane)
catch (FormatException fe)
catch (OverflowException oe)

This is how you would do it in 1.1, unless you first do a sanity check using regular expressions (remember: all input is evil until proven otherwise). So what is wrong here? The point is the exception throwing / catching in itself – it involves a stack walk, which equates to lost performance (especially nasty when we are talking heavy-load Web applications). Wouldn’t it be nice if we could get away without exceptions?

Good news! The BCL data types sport a new method – TryParse. Like the Parse method, it takes the input string as the first parameter. The input is followed by an out parameter, which was the return value of Parse – the return value of TryParse is a simple boolean: did the conversion succeed or did it fail. No exceptions.

The following code snippet shows how easy this is:

double d = 0.0f;
if (!Double.TryParse(val, out d))
// handle error condition

My advice: when porting 1.1 applications to 2.0, make sure that you convert all old Parse code to the new TryParse – your applications will perform and scale a lot better.

Categories: 2 Ohhhh | BCL
Tuesday, July 27, 2004 7:47:44 AM (W. Europe Daylight Time, UTC+02:00)  #    Comments [0]


© Copyright 2020 Christoph Wille

newtelligence dasBlog 2.3.9074.18820
Subscribe to this weblog's RSS feed with SharpReader, Radio Userland, NewsGator or any other aggregator listening on port 5335 by clicking this button.   RSS 2.0|Atom 1.0  Send mail to the author(s)

Don't contact us via this (fleischfalle@alphasierrapapa.com) email address.