lod

lod

  • NA
  • 14
  • 6.1k

How to see if two strings are indentical.

May 19 2005 10:30 AM
As good old structured programmer i like to see if two strings are indentical this way: (stringA == stringB) And, yes, it do what I want. But those who are into object irritated programming soon complain that other languages, like Java, will compare if it is references to the same object, instead of if they contain the same string. Soon a recomendation shows up: (String.Compare(stringA, stringB, false, System.Globalization.CultureInfo.InvariantCulture) == 0) Yes, it still do the same, but ... well ... Argument has that it has far better speed performance. I'm told that the C# compiler optimizes code for speed, and I think that this optimizer should have no problem with such simple expression, so ... eh ...?! And ... to make matters worse ... as far as I'm told ... the first takes into account if they refere to the same object, and thus evaluate very fast if they do!!! So ... What do You think is the best/smartest way of comparing for string equality, and why?

Answers (1)