0
using System;

namespace TakeHome
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("What is the opposite of black ?");

            string answer = Console.ReadLine();

            switch (answer)
            {
                case "Grey" :
                    Console.WriteLine("You are close, but not correct"); 
                    break;

                case "Light":
                    Console.WriteLine("You are close, but try again");
                    break;

                case "White":
                    Console.WriteLine("You are correct");
                    break;

                default:
                    Console.WriteLine("Wrong answer");
                    break;
            }
        }
    }
}

How do i make the user input case-insensitive?

GSerg
  • 76,472
  • 17
  • 159
  • 346
Bliz
  • 1
  • 1
  • 1
    you could always use answer.ToLower() and make the case values lowercase – Luc Apr 22 '21 at 09:30
  • Thank you @Luc , But i want the input to be correct even if the user inputs White , whITe or, wHITe – Bliz Apr 22 '21 at 09:46
  • 2
    Luc meant that you could do something like `switch (answer.ToLower())` and then use `case "grey": case "light": case "white":`, etc. – ProgrammingLlama Apr 22 '21 at 09:50
  • Thank you @Llama , i do get that, but i really do want to know how to make the input case-insensitive without changing the case to lower case or upper case – Bliz Apr 22 '21 at 09:54
  • 1
    [The question](https://stackoverflow.com/questions/2334134/how-to-make-c-sharp-switch-statement-use-ignorecase) I marked yours as a duplicate of has several different solutions. – ProgrammingLlama Apr 22 '21 at 10:26

0 Answers0