Stithaprajyna

I use this blog to jot down what ever comes into my mind or get to see anything I feel is important.

Wednesday, January 18, 2006

Try Parse

For parsing base type the .NET Framework 2.0 introduces a pattern across all the relevant base types called TryParse, which mimics Parse. The difference in behavior is that Parse will throw an exception when the data check fails, while TryParse simply goes to an else statement.

Example:

Dim iVal As Integer

If Int32.TryParse(someString, iVal) Then
' code which deals with the valid integer
Else
' code which deals with an invalid input
End If

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home