Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using equal operators in C#

Tags:

c#

In a If Statement When should I use =, == operators. Is there a === operator ? What is the difference between these operators ?

like image 575
subanki Avatar asked Jan 16 '11 08:01

subanki


People also ask

What is equal operator in C?

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 .

What is the use of == === operators?

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.

Is a == b == C valid in C?

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.


1 Answers

= 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#

like image 79
tenor Avatar answered Sep 23 '22 16:09

tenor