Is it possible to parse a data type (int, double, boolean...) in .NET without throwing an exception and without returning the result? In other words, I just want to be able to answer the question, 'Is this a valid integer?' or 'Is this a valid double?' without having to declare a result variable. I do not want to use .TryParse because I have to pass in a result variable, and I do not want to use .Parse because it will throw.
Any suggestions? (I would be surprised if this functionality wasn't present in .NET, I must be missing something.)
EDIT
Ok, this was too easy... just made a couple extension methods and I'm on my way...
<Extension()> _
Public Function IsValidInteger(ByVal value As String) As Boolean
Dim result As Integer
Return Integer.TryParse(value, result)
End Function
<Extension()> _
Public Function IsValidDouble(ByVal value As String) As Boolean
Dim result As Double
Return Double.TryParse(value, result)
End Function
Looks like this a duplicate question, however, in all honesty, I didn't find this one until now:
Integer.TryParse - a better way?
The accepted answer from that question is probably better than anything suggested here.