Difference between is and ==
bearophile
bearophileHUGS at lycos.com
Tue Feb 4 00:51:33 PST 2014
Suliman:
> What difference between
> if ((x = stdin.readln().chomp) is "q")
> and
> if ((x = stdin.readln().chomp) == "q")
>
> ?
"is" performs a raw comparison of just the values, and the value
of a string is its ptr and length field. While "==" compares
their contents. So you want to use "==" here because you are
interested to see if x contains the char 'q', because while their
lengths could be equal, their ptr is surely different.
Bye,
bearophile
More information about the Digitalmars-d-learn
mailing list