I think they had published this question yesterday
How to evaluate that the received data is decimal without using an exception and that these data, which are two values A and B, are between the following ranges:
A value between -150 and 150
B value between -100 and 100
Today I started working on it and after having achieved the code that evaluated it, when I started to publish the answer, I found that it had been deleted by the author
So taking advantage of the fact that I already had the code, I will answer myself
Here is an option using
Decimal.TryParse (string s, out decimal result);
Link to documentation .Copy and paste this into
static void Main(string[] args)
a new console application and run it to see the results:I ask for the values by console, but it is assumed that in your program you would receive them from some part of the program, that is why I do not put the evaluation of the values in a loop until they reach the allowed value ranges and I limit myself to saying if it is or not between the requested ranges
To evaluate that the data given by the keyboard is decimal, not being able to use the exception, since it was one of the requirements requested in the question, I use an evaluation so that when going through the string values that correspond to the decimal numbers given by the keyboard, they contain the decimal point.
this was the code i had come up with