Newbie here, any help understanding is appreciated. First experience with tryparse.
In this instance:
do
{
Console.Write("What is the temperature (in degrees Fahrenheit): ");
outcome = double.TryParse(Console.ReadLine(), out tempf);
if (outcome == false)
{
Console.WriteLine("Invalid input");
}
} while (outcome == false);
A user input of 'stack' would return a boolean 'false' value, whereas an input such as '100' would return as 'true'.
I am under the impression that double.TryParse would only return true if the user input is of string type, as this would be a successful parse.
double.TryParsetakse astringand tries to convert it todouble. So the string must contain only digits. "100" is astringthat contains only numbers an thus can be parsed. "stack" is astring, but contains chars that are not digit, and thus cannot be parsed"100"that was read from the input is a string. A string that can be parsed to a double value100.0.double.TryParsereturnedtrueonly there would be no reason to return it all