-
Notifications
You must be signed in to change notification settings - Fork 173
Closed
Description
P.75 "The result is that the number variable is available from both the true and false consequence of the if statement but not outside the if statement."
In fact, the variable is still in scope outside of the if block.
// double number;
string input;
System.Console.Write("Enter a number: ");
input = System.Console.ReadLine();
if (double.TryParse(input, out double number))
{
System.Console.WriteLine($"input was parsed successfully to {number}.");
}
else
{
// Note: number scope is here too (although not assigned)
System.Console.WriteLine("The text entered was not a valid number.");
}
System.Console.Write($"the value of number is {number}.");
How do I modify the statement of the text?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
