It tells me that it can't convert int to bool. Tried TryParse but for some reason the argument list is invalid.
Code:
private void SetNumber(string n)
{
// if user input is a number then
if (int.Parse(n))
{
// if user input is negative
if (h < 0)
{
// assign absolute version of user input
number = Math.Abs(n);
}
else
{
// else assign user input
number = n;
}
}
else
{
number = 0; // if user input is not an int then set number to 0
}
}
There are a lot of problems with this code:
But try this:
Well for one thing the inner if statement has an 'h' instead of an 'n' if(h < 0). But TryParse should work there assuming that 'number' is a class variable.
You were probably very close using
TryParse
, but I'm guessing you forgot theout
keyword on the parameter:You can try with some simple regular expression :