Sunday, January 01, 2006

TryParse

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