您的位置:首页 > 编程语言 > C#

C# ignoring letter case for if statement(Stackoverflow)

2016-01-29 12:20 316 查看
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") { }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: