When comparing strings, you should use methods that explicitly indicate which comparison you intend to perform. This makes your code much more convenient and readable. If possible, use the overloads of the methods of the System.String and System.Array classes that take the StringComparison enumeration parameter so that you can specify what type of comparison to perform. It is better to avoid using the == and! = Operators when comparing strings. Also avoid using instance methods of String.CompareTo, because none of the overloads accepts the StringComparison parameter.
Depending on your needs, you can use the following methods:
bool result = root.Equals(root2, StringComparison.Ordinal); result = root.Equals(root2, StringComparison.OrdinalIgnoreCase); bool areEqual = String.Equals(root, root2, StringComparison.Ordinal);
Source for this answer: http://msdn.microsoft.com/en-us/library/cc165449.aspx
source share