Skip to content

Latest commit

 

History

History
49 lines (36 loc) · 1.03 KB

SA1122.md

File metadata and controls

49 lines (36 loc) · 1.03 KB

SA1122

TypeName SA1122UseStringEmptyForEmptyStrings
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 = "";

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.")]
#pragma warning disable SA1122 // UseStringEmptyForEmptyStrings
#pragma warning restore SA1122 // UseStringEmptyForEmptyStrings