public void Main()
{
string s = "";
if (s == "") // Non-compliant
{
Console.WriteLine("Empty string");
}
}
Use string.Length instead of comparison with empty string
Comparing a string to an empty string is unnecessary and can be replaced by a call to string.Length, which is more performant and more readable.
This rule should not be ignored.
public void Main()
{
string s = "";
if (s == "") // Non-compliant
{
Console.WriteLine("Empty string");
}
}
public void Main()
{
string s = "";
if (s.Length == 0) // Compliant
{
Console.WriteLine("Empty string");
}
}