Alex Alex - 27 days ago 19
C# Question

C# shorthand for 2 or conditions

I have the following statement in C#

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


My question is, is there a way to write this in shorthand eg;

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

Answer

How about

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