If statements and && or ||

后端 未结 12 1353
臣服心动
臣服心动 2020-12-22 02:54

OK so I\'m a beginner with C# and I am having trouble understanding the if statement below.

For this example INumber is declared as 8, dPrice is 0 and dTAX is 10.

12条回答
  •  余生分开走
    2020-12-22 03:51

    Use

    if (iNumber != 8 && iNumber != 9)
    

    This means "if iNumber is not equal to eight and iNumber is not equal to nine". Your statement:

    if (!Number != 8 || iNumber != 9)
    

    Means "if !iNumber is not equal to eight or iNumber is not equal to nine" which is true as long as iNumber is not equal to one of those values, and because it can only hold one value and not two simultaneously, this statement will always be true.

提交回复
热议问题