Test for empty strings using string length, not string.Empty or "" to get the best performance.
Because of the implementation of the string class, the most performant method for testing for an empty string is to test for the string length equal to zero. Other methods are effective, but are less performant.
NOTE: It is important to also understand that testing for length on a null string will throw an exception while using Object.Equals does not throw an exception. This rule's correction will test for a null prior to testing for string.Length in situations where Object.Equals is used.
All rule violations are can be automatically corrected with devAdvantage.
[C#]
public string bar(string foo )
{
string test;
if(foo == string.Empty ) //Very slow
test = "Very slow";
if ( foo == "" ) //Slow
test = "Slow";
if(foo != null && foo.Length == 0 ) //Most performant way to test for empty string else if ( foo
test = "Fast";
return test;
}