Arjan's World: .NET 2.0 Tip: Please Understand The Meaning of .TryParse
You are now being redirected to the new housing of Arjan's World. Click here in case nothing happens

Wednesday, October 04, 2006

.NET 2.0 Tip: Please Understand The Meaning of .TryParse

.NET 2.0 has this nice method called .TryParse. It will Try to Parse something for you, be it some Integer, String, Boolean or Date. Then it let's you know if it succeeded. This means e.g. that a Boolean.TryParsewill return True if it can convert your input to a boolean.

So *don't* try something like this:

blnValue = Boolean.TryParse(stringContainingBooleanValue, blnValue)

It will happily return True when the string contains either "True" or "False" :-)



Post a Comment

<< Home