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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticleUsing == 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
More Pages to Explore .....