Rule Definition
If you want to test for empty strings, test the length (compare with 0) of the string instead. This is over twice as quick. Also as String objects can be null, you can use String.IsNullOrEmpty instead - however, do not compare it to true (ie not if (StringIsNullOrEmpty (myString) == true), just use: if (StringIsNullOrEmpty (myString) ).
Remediation
Test the length of the string to 0. Alternatively, you can use the String.IsNullOrEmpty method for better robustness.
Violation Code Sample
If ( MyString == String.Empty ) ,,,
Fixed Code Sample
If ( MyString.Length == 0) ..
or Better for reliability
if ( String.IsNullOrEmpty( MyString) )
Reference
http://dotnetperls.com/Content/IsNullOrEmpty-Samples.aspx, http://www.csharper.net/blog/string_empty_vs_empty_quotes___quot__quot___vs_string_length.aspx, http://codebetter.com/blogs/brendan.tompkins/archive/2003/10/14/2585.aspx, http://dotnetperls.com/fxcop-performance-warnings
Related Technologies
.Net
Technical Criterion
Efficiency - Memory, Network and Disk Space Management
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.