bool result = Int32.TryParse(someString, out someNumeric)
This method will try to convert someString
into someNumeric
, and return a result
depends if the conversion is successful, true
if conversion is successful and false
if conversion failed. Take note that this method will not throw exception if the conversion failed like how Int32.Parse
method did and instead it returns zero for someNumeric
.
For more information, you can read here:
https://msdn.microsoft.com/en-us/library/f02979c7(v=vs.110).aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-2
&
How to convert string to integer in C#