Using == or Equals for string comparison

后端 未结 5 1099
抹茶落季
抹茶落季 2020-12-14 23:48

In some languages (e.g. C++) you can\'t use operators like == for string comparisons as that would compare the address of the string object, and not the string itself. Howev

5条回答
  •  佛祖请我去吃肉
    2020-12-15 00:24

    generally speaking, == does pointer equality, while .equals checks whether the attributes are equal. So if you did something like

    a = 'a';
    b = 'a';
    bool c = (a == b);
    bool d = (a.Equals(b))
    

    then c should return false and d should be true.

提交回复
热议问题