coderushforroslyn-115606-refactoring-assistance-use-string-compare.md
Replaces the equality expression between two strings with the String.Compare method call. The String.Compare method is more flexible than the equality operator. For example, you can specify whether to ignore the letter case while comparing strings. This method also has better performance.
Available when the caret is on an equality expression between two strings.
Place the caret on the equality expression between two strings.
Press the Ctrl + . or Ctrl + ~ shortcut to invoke the Code Actions menu.
Select Use String.Compare from the menu.
After execution, the Refactoring converts the comparison with the equality operator to the comparison with the String.Compare method.
bool CheckError(string msg) {
if (String.Compare(msg.Substring(1, 4), "rror", StringComparison.Ordinal) == 0)
return true;
return false;
}
Function CheckError(ByVal msg As String) As Boolean
If String.Compare(msg.Substring(1, 4), "rror", StringComparison.Ordinal) = 0 Then
Return True
End If
Return False
End Function
See Also