Table of Contents

SA1311: Static readonly fields should begin with upper-case letter

Cause

The name of a static readonly field does not begin with an upper-case letter.

Rule description

A violation of this rule occurs when the name of a static readonly field begins with a lower-case letter.

C# 8 added readonly members for structs; this rule still only targets static readonly fields and ignores readonly methods, properties, indexers, or events. Accessible static readonly fields can also trigger SA1307, while SA1304 does not report static readonly fields. This prevents all three naming rules from firing on the same field while keeping static readonly fields covered.

How to fix violations

To fix a violation of this rule, change the name of the field so that it begins with an upper-case letter.

How to suppress violations

[SuppressMessage("StyleCop.CSharp.NamingRules", "SA1311:StaticReadonlyFieldsMustBeginWithUpperCaseLetter", Justification = "Reviewed.")]
#pragma warning disable SA1311 // StaticReadonlyFieldsMustBeginWithUpperCaseLetter
#pragma warning restore SA1311 // StaticReadonlyFieldsMustBeginWithUpperCaseLetter