C# ignoring letter case for if statement(Stackoverflow)

Question:

I have this if statement:

if (input == 'day')
    Console.Write({0}, dayData);

When the user types 'day' it should be so that the console writes the data in that array. It works fine but is there anyway to get it to work if the user types 'DaY' or 'dAy' etc. I know I could do:

if (input == 'day' || input == 'dAy' || input == 'DaY')
     Console.WriteLine({0}, dayData);

But is there anyway to make it shorter and tidier?

Thanks.

Answer:


if (input.ToLower() == "day") { }


原文地址:https://www.cnblogs.com/lcchuguo/p/5168599.html