To verify if user input is a double
in C#, you can use the double.TryParse
or double.Parse
method.
double.TryParse
returns a boolean value indicating whether the conversion was successful, and the parsed value is returned as an out parameter.
Here is an example:
main.cs253 chars13 lines
Alternatively, you can use double.Parse
, which throws an exception if the input is not a valid double.
main.cs231 chars11 lines
Note that double.Parse
can also throw other exceptions, like ArgumentNullException
or OverflowException
.
gistlibby LogSnag