c# - Is there a way that I can avoid an if statement full of checks
问题描述
My code looks like this:
if (Settings.cc == CC.F1 || Settings.cc == CC.F2)
with additional tests for F3, F4 and F5
is there any way that I can avoid checking against Settings.cc for every entry?
解决方案
您可以执行以下操作:
if (new[] {CC.F1, CC.F2, CC.F3, CC.F4, CC.F5}.Contains(Settings.cc))
推荐阅读
- sendgrid - 到 Gmail 的 Sendgrid 电子邮件路由
- go - 来自 Goroutine 通道的随机结果,该通道接收指向底层对象的指针
- javascript - 从 php 调用函数时重置 Javascript 全局变量
- python-3.x - Reshaping nested numpy array,
- reactjs - reactjs 应用程序 - 无法显示我的 hello world
- python - 如何将图像的总和除以opencv中的图像总数
- python - 更多pythonic方式来编辑列值 - python pandas
- javascript - 如何在打字稿地图方法中使用javascript查找表?
- javascript - 多么不明白这段代码是什么:Javascript
- c# - 设置类实例中的变量后运行类初始化函数的优雅解决方案