<2017 July>
SunMonTueWedThuFriSat
2526272829301
2345678
9101112131415
16171819202122
23242526272829
303112345

On this page...

Search

Links

Member of...


ASP Insiders

MVP Visual Developer ASP/ASP.NET

Enter CodeZone

Blog Categories

Microsoft

Blogroll

Deutsche Resourcen

Management

Sign In
 

#  Wednesday, 08 November 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, 08 November 2006 15:04:26 (W. Europe Standard Time, UTC+01:00)  #    Comments [0]

 



#  Wednesday, 09 March 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, 09 March 2005 17:03:33 (W. Europe Standard Time, UTC+01:00)  #    Comments [0]

 



#  Tuesday, 22 February 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, 22 February 2005 02:12:03 (W. Europe Standard Time, UTC+01:00)  #    Comments [0]

 



#  Tuesday, 27 July 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;
try
{
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, 27 July 2004 07:47:44 (W. Europe Daylight Time, UTC+02:00)  #    Comments [0]

 



© Copyright 2017 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.