在C#中的if语句中测试多个值

Ada*_*ive 5 c# syntax if-statement

在C#中是否有简写语法来实现:

if ((x == 1) || (x==2) || (x==5) || (x==13) || (x==14))
Run Code Online (Sandbox Code Playgroud)

......更短?像(假设)的东西

if (x in {1, 2, 5, 13, 14})
Run Code Online (Sandbox Code Playgroud)

我"觉得"它存在,我只是在精神上和Googly短暂.实际上,我必须经常测试一堆枚举,这是不可读的.如果语言已经支持,我也讨厌做一个小帮助函数.

提前致谢!

编辑

有一些聪明的解决方案涉及列表...但我希望有一种纯粹的逻辑结构.如果它不存在,那就这样吧.谢谢!

das*_*ght 12

试试这个:

if ((new[]{1, 2, 5, 13, 14}).Contains(x)) ...
Run Code Online (Sandbox Code Playgroud)