I am trying to cast a string to double, but I don't want it to throw exception, but to return some value. I found the TryCast function but it seems I am not using it right. I try TryCast(string, Double)
and it says that "Double" is a value type, not a reference type. What am I doing wrong?
TryParse(String, Double) Converts the string representation of a number to its double-precision floating-point number equivalent. A return value indicates whether the conversion succeeded or failed.
TryCast returns Nothing, so that instead of having to handle a possible exception, you need only test the returned result against Nothing . You use the TryCast keyword the same way you use the CType Function and the DirectCast Operator keyword.
Double.TryParse(string, double)
You should use the TryParse method instead.
You should try this:
If Double.TryParse(value, New Double) Then
' TODO
end if
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With