In a If Statement When should I use =, == operators. Is there a === operator ? What is the difference between these operators ?
The equality operators, equal to ( == ) and not equal to ( != ), have lower precedence than the relational operators, but they behave similarly. The result type for these operators is bool . The equal-to operator ( == ) returns true if both operands have the same value; otherwise, it returns false .
The strict equality operator ( === ) checks whether its two operands are equal, returning a Boolean result. Unlike the equality operator, the strict equality operator always considers operands of different types to be different.
if (a == b && b == c) .... In this case, a == b will return true, b == c will return true and the result of the logical operation AND will also be true.
= is assignment, like in
var i = 5;
Do not use this operator in the if statement.
== is for comparison like in
if(i == 6){...}
there is no === operator in C#
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With