-
Notifications
You must be signed in to change notification settings - Fork 22
SA1122
Christophe HEISER edited this page Aug 18, 2015
·
6 revisions
<title>SA1122: UseStringEmptyForEmptyStrings</title>
<script src="script/helpstudio.js" type="text/javascript"></script>
<script src="script/StandardText.js" type="text/jscript"></script>
<script type="text/jscript">WritePageTop(document.title);</script>
TypeName |
UseStringEmptyForEmptyStrings |
CheckId |
SA1122 |
Category |
Readability Rules |
The C# code includes an empty string, written as “”.
A violation of this rule occurs when the code contains an empty string. For example:
string s = "";
string s = @"";
string s = $"";
This will cause the compiler to embed an empty string into the compiled code. Rather than including a hard-coded empty string, use the static string.Empty property:
string s = string.Empty;
To fix a violation of this rule, replace the hard-coded empty string with string.Empty.
[SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1122:UseStringEmptyForEmptyStrings", Justification = "Reviewed.")]
- - SA0102 - Clean Install
- - Download
- - Documentation Rules - Layout Rules - Maintainability Rules - Naming Rules - Ordering Rules - Readability Rules - Spacing Rules - Suppressions
- - Adding a custom StyleCop settings page - Adding custom rule settings - Authoring a custom styleCop rule - Authoring rules metadata - Custom CSharp Language Service - Custom MSBuild Integration - Hosting StyleCop in a Custom Environment - Installing a Custom Rule - Integrating StyleCop Into Build Environments - Integrating StyleCop into MSBuild - Writing Custom Rules for StyleCop