Hello,
When you do something like this :
C#if (myVar == "test")
{
// ....
}
The CRR refactoring propose : "Use string.Compare" the result is :
C#if (string.Compare(myVar, "test", false) == 0)
return null;
It's much more better like this :
C#if (string.Compare(myVar, "test", StringComparison.OrdinalIgnoreCase) == 0)
return null;
and propose the options available :
- CurrentCulture Performs a case-sensitive comparison using the current culture.
- CurrentCultureIgnoreCase Performs a case-insensitive comparison using the current culture.
- InvariantCulture Performs a case-sensitive comparison using the invariant culture.
- InvariantCultureIgnoreCase Performs a case-insensitive comparison using the invariant culture.
- Ordinal Performs an ordinal comparison.
- OrdinalIgnoreCase Performs a case-insensitive ordinal comparison.
it's clearer and based on the "Best Practices for Using Strings in .NET" here : MSDN
Best regards,
Hello Christian,
Thank you for your suggestion and arguments. We carefully reviewed them and came to the conclusion that you are right and we should use more explicit comparison options here. We will change this refactoring's resulting code, so it uses the StringComparison.Ordinal compare option.