«

Forget Longhorn, what about TryParse?

Ok, don’t forget Longhorn, I’m just kidding. At the same time, I think the overall greatness that is Longhorn (and Avalon, and WinFS) has kind of drowned out some of the cool stuff available in the Whidbey release of the .Net Framework. My favorite (for the moment) is something small but exceedingly obvious.

If you’ve written C# code, you’ve probably had to do something like this quite a few times:

 function isNumberic() {     try     {       int.Parse(myValue);         return true;    }   catch(FormatException fex)  {       return false;   } }

That’s because the 1.0 and 1.1 versions of the framework don’t support any other method for determining whether a string can be interpreted as an integer or any of the other base types that support parse.

Well, Whidbey introduces the TryParse method which accomplishes the same thing the isNumeric function I wrote earlier in the post does, but without using Exceptions. That means big performance gains, because Exceptions are pretty expensive. Beyond that, exceptions are intended to be used for *ahem* exceptional cases, not for running tests.

Once again MS shows that it’s really listening to the feedback that they get from the community.

Ok, let me stop typing so I can pay attention to this session.