-4

Any easier way to write this if statement

if (value1 <= 0 || value2 <= 0)

For example some think like if ((value1 || value2) <= 0

Rene Nielsen
  • 87
  • 1
  • 7

2 Answers2

3

No, your way is correct. If you have more than two values and you want to know if any of them is less than or equal to zero use an array

if(new [] { value1, value2, value3, ... }.Any(x => x <= 0))
Selman Genç
  • 100,147
  • 13
  • 119
  • 184
0

in this case :

if (value1 <= 0 || value2 <= 0)

if value1 <=0 is true then it will short circut the evaluation and directly go inside the if loop as

1 || 0 = 1
1 || 1 = 1
Sagar Pilkhwal
  • 3,998
  • 2
  • 25
  • 77