I think
if( newItem.ReceiptNo != 0 && newItem.ReceiptYear != 0 && newItem.SR != 0)
and
if( ! ( newItem.ReceiptNo == 0 && newItem.ReceiptYear == 0 && newItem.SR == 0))
Should be same. But I am not getting same result on android
I think
if( newItem.ReceiptNo != 0 && newItem.ReceiptYear != 0 && newItem.SR != 0)
and
if( ! ( newItem.ReceiptNo == 0 && newItem.ReceiptYear == 0 && newItem.SR == 0))
Should be same. But I am not getting same result on android
Logic doesn't work that way.
if( newItem.ReceiptNo != 0 && newItem.ReceiptYear != 0 && newItem.SR != 0)
is the same as
if( ! ( newItem.ReceiptNo == 0 || newItem.ReceiptYear == 0 || newItem.SR == 0))
Notice the ||
instead of &&
.
See also: De Morgan's Laws
You would be wrong, carry out the negation on your second if
if (newItem.ReceiptNo != 0 || newItem.ReceiptYear != 0 || newItem.SR != 0)
Remember the negation of and
is or
.
Statement 1
if(newItem.ReceiptNo != 0 && newItem.ReceiptYear != 0 && newItem.SR != 0)
This means that all 3 should not be zero
Statement 2
if( !(newItem.ReceiptNo == 0 && newItem.ReceiptYear == 0 && newItem.SR == 0))
first
newItem.ReceiptNo == 0 && newItem.ReceiptYear == 0 && newItem.SR == 0
means all 3 should be zero and not of this means any of the 3 should not be zero
to this to be same change this with
if( !(newItem.ReceiptNo == 0 || newItem.ReceiptYear == 0 || newItem.SR == 0))
for eg
a != b is equal to !(a=b)
(a != b && a != c) is equal to !(a=b || a=c)
(a != b || a != c) is equal to !(a=b && a=c)
whenever !operator comes out and applied on result of some operations then it will revert all opertion like && will convert into || and || will convert into &&.
Even if there was noticeable difference, I think compilers are smart enough to care for such things. So my advice is to use what makes the code easier to understand, and leave micro-optimizations to the compiler.
See : Is the inequality operator faster than the equality operator?