Why does this simple If statement go to the Else Sequence?

Hello @Peter_Peter,

Try comparing with the following sentence:
variable1.Equals(variable2).

The Is operator is not adequate when comparing two String variables. According Microsoft’s documentation:

Is Operator − It compares two object reference variables and determines if two object references refer to the same object without performing value comparisons.

In this cases, it’s better to use some native String comparators.

Regards,
Alan C.

Hi @Peter_Peter

You can also just use the “=” - operator. Then it’s working properly.

Regards,
Luca H.

I know that this is an option. But im wondering why this if statement goes into the Else sequence.
Because if I use “Isnot” then it goes into the Then sequence.

@Peter_Peter
It goes to the Else because variable1 is not variable2. They have the same value but as @mancl0ud said the Is operator checks to see if they refer to the same object.