Skip to content
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

Cause

The C# code includes an empty string, written as “”.

Rule Description

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;

How to Fix Violations

To fix a violation of this rule, replace the hard-coded empty string with string.Empty.

How to Suppress Violations

[SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1122:UseStringEmptyForEmptyStrings", Justification = "Reviewed.")]
Clone this wiki locally