CRR0050 - String.Compare can be used
This analyzer identifies string comparison expressions which can be replaced with a string.Compare call to improve code readability and provide comparison options.
bool CheckError(string msg) {
if (msg.Substring(1, 4) == "Error")
return true;
return false;
}
To fix this issue, use the string.Compare method call instead of the “==” (“=” in Visual Basic) or “!=” operator (“<>” in Visual Basic):
bool CheckError(string msg) {
if (string.Compare(msg.Substring(1, 4), "Error", false) == 0)
return true;
return false;
}
Call the Use string.Compare refactoring to convert the comparison with the equality operator or inequality operator to a comparison with the string.Compare method.