C#简写为2或条件

时间:2016-11-07 12:54:08

标签: c#

我在C#中有以下声明

if(user.member.RegistrationDate.Value.Month == 10 || user.member.RegistrationDate.Value.Month == 11)

我的问题是,有没有办法用速记来写这个;

if(user.member.RegistrationDate.Value.Month == 10 || 11)

1 个答案:

答案 0 :(得分:6)

怎么样

 if (new []{10,11}.Contains( user.member.RegistrationDate.Value.Month))