C# ignoring letter case for if statement(Stackoverflow)

来源:互联网 发布:淘宝消费 信用卡积分 编辑:程序博客网 时间:2024/06/18 08:12

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") { }


0 0