Configuring Hungarian Notation Rules

By default, Microsoft StyleCop does not allow variable or field names to include Hungarian notation. This is enforced by rule SA1305, FieldNamesMustNotUseHungarianNotation.

The implementation of this rule is rather straightforward, assuming that any field or variable name which begins with one or two lower-case letters and is followed by an upper-case letter is guilty of using Hungarian notation. This is true in many cases such as sName, nAmount, ulCost, etc. However, this simple algorithm does not hold true for variables with names like isValid, doTask, onAction, etc. Each of these names begins with two lower-case letters followed by an upper-case letter, but none are using Hungarian notation.

StyleCop provides a mechanism for specifying one or two letter prefixes which are allowed to be used at the start of variable and field names. This list can be set for a project by bringing up the settings dialog for the project, and navigating to the Hungarian tab:

Hungarian Notation Settings

It may be desirable to provide this list within a parent settings file at the root of your development tree, so that these prefixes will be allowed on all projects within your environment. To learn how to share settings across multiple projects, click here.

Skip to main content