0

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)
Alex
  • 3,730
  • 9
  • 43
  • 94
  • 1
    If those are expensive getters of properties (or you just want to make it more readable) it may make sense to simply get value into temp variable: `var value = user.member.RegistrationDate.Value.Month;` and then you can `if(value == 10 || value == 11) { ... }`. – Sinatr Nov 07 '16 at 12:59

1 Answers1

5

How about

 if (new []{10,11}.Contains( user.member.RegistrationDate.Value.Month))
fubo
  • 44,811
  • 17
  • 103
  • 137