C#C
C#2y ago
Mathall

possible null reference warning

C#
static string? GetName()
        {
            string? input = default;
            bool needName = true;
            while (needName)
            {
                Console.WriteLine("What is your name?");
                input = Console.ReadLine();

                if (!input.All(char.IsLetterOrDigit) || String.IsNullOrEmpty(input)) //!!!
                {
                    Console.WriteLine("Please make sure that the name only contains letters or digits!");
                }
                else
                {
                    needName = false;
                }
            }
            return input;
        }
image.png
Was this page helpful?