Quantcast
Channel: Using == or Equals for string comparison - Stack Overflow
Browsing all 6 articles
Browse latest View live

Answer by Hans Passant for Using == or Equals for string comparison

This is the implementation of the operator: public static bool operator == (String a, String b) { return String.Equals(a, b); }Don't lose any sleep over this.

View Article



Answer by Ritwik Bose for Using == or Equals for string comparison

generally speaking, == does pointer equality, while .equals checks whether the attributes are equal. So if you did something likea = 'a';b = 'a';bool c = (a == b);bool d = (a.Equals(b))then c should...

View Article

Answer by Steve De Caux for Using == or Equals for string comparison

Best-practise-wise, I would tend to always use an Equals() function for string comparison. This makes it clear when someone else reads your code that you specifically want the strings compared.

View Article

Answer by yu_sha for Using == or Equals for string comparison

There is no technical difference (unless aa is null). Use whatever looks better to you. In my opinion, using operator overloads makes the code clearer.Use functions when you need (or might need in...

View Article

Answer by Marc Gravell for Using == or Equals for string comparison

I wouldn't use:aa.Equals(bb)unless I knewaa couldn't possibly be null. I might use:string.Equals(aa,bb)But I'd mainly use that it I wanted to use one of the specific StringComparison modes (invariant,...

View Article


Using == or Equals for string comparison

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. However, in C# you can use == to...

View Article
Browsing all 6 articles
Browse latest View live




Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>
<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596344.js" async> </script>