Skip to content

use-string-empty

C#stylefix: safedefault: offcsharp/stylecop

Reports "" (or @"") where string.Empty can be used. It is not reported where a constant is required: const, attribute arguments, default parameter values, case labels and patterns.

string.Empty states that the string is empty on purpose, while "" can be a value that was forgotten. It is a convention that some projects choose and others do not.

To fix, write string.Empty.

Reported
...
string F(string s = "") {
...
switch (s) { case "": break; }
return s ?? @"";
}
[System.Obsolete("")] void G() { }
}
After the fix
...
string F(string s = "") {
...
switch (s) { case "": break; }
return s ?? string.Empty;
}
[System.Obsolete("")] void G() { }
}
csharp:
lint:
rules:
use-string-empty: warn # off (default), warn, error

Enabled by the presets: csharp/stylecop.

Suppress one line with sudsy-disable-next-line use-string-empty in a comment of the file’s language.

The same check in other tools. full: Sudsy reports what the upstream rule reports; partial: only part of it, as the last column says.

Tool Rule Match What differs
StyleCop SA1122 partial Only the string.Empty direction; no option for the opposite style (RCS1078) because no preset needs it