SA1401: FieldsMustBePrivate

StyleCop

TypeName

FieldsMustBePrivate

CheckId

SA1401

Category

Maintainability Rules

Cause

A field within a C# class has an access modifier other than private.

Rule Description

A violation of this rule occurs whenever a field in a class is given non-private access. For maintainability reasons, properties should always be used as the mechanism for exposing fields outside of a class, and fields should always be declared with private access. This allows the internal implementation of the property to change over time without changing the interface of the class.

Fields located within C# structs are allowed to have any access level.

How to Fix Violations

To fix a violation of this rule, make the field private and add a property to expose the field outside of the class.