❔ Dereference of a possibly null reference.
do {
try {
choice = char.Parse(Console.ReadLine().ToUpper()); // <<< this line throws the warning
switch (choice) {
case 'P':
Console.WriteLine("Ok");
break;
case 'Q':
Environment.Exit(0);
break;
default:
Console.Write("Try again: ");
break;
}
}
catch (Exception) {
Console.Write("Try again: ");
}
}
while (choice != 'P' || choice != 'Q'); do {
try {
choice = char.Parse(Console.ReadLine().ToUpper()); // <<< this line throws the warning
switch (choice) {
case 'P':
Console.WriteLine("Ok");
break;
case 'Q':
Environment.Exit(0);
break;
default:
Console.Write("Try again: ");
break;
}
}
catch (Exception) {
Console.Write("Try again: ");
}
}
while (choice != 'P' || choice != 'Q');