Skip to content

field-name-no-underscore

C#styleno fixdefault: offcsharp/stylecop

Reports a field whose name begins with an underscore. The option fields is the expression a field name must match.

The convention of many style guides names fields in camel case without a prefix and tells them from locals by writing this.. A leading underscore is the other convention; a project picks one, and the rule enforces it.

To fix, rename the field.

Reported
class C
{
private int _count;
private int count;
}
csharp:
lint:
rules:
field-name-no-underscore:
level: warn # off (default), warn, error
options:
fields: "^[^_]"
Option Type Default Description
fields string "^[^_]" Regular expression the name of a field must match; empty: not checked.

Enabled by the presets: csharp/stylecop.

Suppress one line with sudsy-disable-next-line field-name-no-underscore in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
StyleCop SA1309 full