2016-11-07 51 views
0

我在C#下面的语句C#简写为2个或条件

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

我的问题是,有没有写这个速记例如一种方式;

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

如果这些都是性能的昂贵干将(或者你只是想使其更具可读性)意义只是获得价值为临时变量:'VAR值=用户.member.RegistrationDate.Value.Month;'然后你可以'if(value == 10 || value == 11){...}'。 – Sinatr

回答

6

它可能如何

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