C# ignoring letter case for if statement(Stackoverflow)
2016-01-29 12:20
316 查看
Question:
I have this if statement:
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:
But is there anyway to make it shorter and tidier?
Thanks.
Answer:
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") { }
相关文章推荐
- C#中Abstract和Virtual
- C#特性详解
- 9.5 在 C# 中使用 F# 库
- C# 事务处理
- C# 如何提取SaveFileDialog的保存路径
- C#:抽象类PK密封类
- C#基础——与C#的第一次邂逅
- c#中DataTime类型的常用操作整理
- C#多线程简单例子讲解
- c# 6.0新特性(一)
- c# 调用outlook发送邮件
- C# WINFORM判断程序是否运行,且只能运行一个实例
- C# 获取时间
- C#多线程编程
- C#中将DataTable中数据导出到csv文件中
- C#绘制柱形图、饼图、曲线图
- C# 自定义exe引用的dll路径
- C#中的字符串
- 关于C# 耗时操作的时间查看
- 寒假C#学习笔记。。。