Richard
Richard
CC#
Created by GreenMile on 8/30/2024 in #help
Beginner questions. prevent unhalted exception
Also ReadLine() should be used if entering a line of text, versus ReadKey() is more suited to single key presses.
39 replies
CC#
Created by GreenMile on 8/30/2024 in #help
Beginner questions. prevent unhalted exception
If it's not null, it will check if it's not y or n, then continue.
39 replies
CC#
Created by GreenMile on 8/30/2024 in #help
Beginner questions. prevent unhalted exception
there you will first check if it's a null value, then continue loop.
39 replies
CC#
Created by GreenMile on 8/30/2024 in #help
Beginner questions. prevent unhalted exception
If it does throw an exception, change the while portion to : while (userInput == null || (userInput != "y" && userInput != "n")
39 replies
CC#
Created by GreenMile on 8/30/2024 in #help
Beginner questions. prevent unhalted exception
so there's no way to get a null.
39 replies
CC#
Created by GreenMile on 8/30/2024 in #help
Beginner questions. prevent unhalted exception
With the loop I shared, the loop will never exit unless one of the values is y or n.
39 replies
CC#
Created by GreenMile on 8/30/2024 in #help
Beginner questions. prevent unhalted exception
ok. So what's happening is this... When you press CTRL Z, you are allowing null item to be passed to your variable. Then when you try to output your variable, it is null = has no value, and hence the compiler doesn't know what to do and throws an exception.
39 replies
CC#
Created by GreenMile on 8/30/2024 in #help
Beginner questions. prevent unhalted exception
how are you aborting the loop?
39 replies
CC#
Created by GreenMile on 8/30/2024 in #help
Beginner questions. prevent unhalted exception
do you mean Unhandled?
39 replies
CC#
Created by GreenMile on 8/30/2024 in #help
Beginner questions. prevent unhalted exception
@GreenMile Unhalted Exception?
39 replies
CC#
Created by GreenMile on 8/30/2024 in #help
Beginner questions. prevent unhalted exception
The bonus of the do ... while approach is that it prevents any other characters from being accepted, so you don't have all the edge cases to worry about.
39 replies
CC#
Created by GreenMile on 8/30/2024 in #help
Beginner questions. prevent unhalted exception
true, but is a more direct solution to the problem.
39 replies
CC#
Created by GreenMile on 8/30/2024 in #help
Beginner questions. prevent unhalted exception
char userInput; do { Console.Write("Enter 'y' or 'n': "); userInput = Console.ReadKey().KeyChar; Console.WriteLine(); } while (userInput != 'y' && userInput != 'n');
39 replies
CC#
Created by GreenMile on 8/30/2024 in #help
Beginner questions. prevent unhalted exception
If you want to limit to Y & N respectively, I would use this approach:
39 replies
CC#
Created by hunterlan on 8/27/2024 in #help
Blazor Static SSR - redirect after form submission
What's the exception?
8 replies