C#C
C#4y ago
bialasik__

❔ 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');
Was this page helpful?