All rules
CA1028Design Enabled by default: No

Enum storage should be Int32

Enum storage should be Int32

Microsoft docs

Description

An enumeration is a value type that defines a set of related named constants. By default, the System.Int32 data type is used to store the constant value. Even though you can change this underlying type, it is not necessary or recommended for most scenarios. No significant performance gain is achieved by using a data type that is smaller than System.Int32. If you cannot use the default data type, you should use one of the Common Language System (CLS)-compliant integral types, System.Byte, System.Int16, System.Int32, or System.Int64 to make sure that all values of the enumeration can be represented in CLS-compliant programming languages.

Cause

The underlying type of an enumeration is not System.Int32.

By default, this rule only looks at externally visible enumerations, but this is configurable.

How to fix violations

To fix a violation of this rule, unless size or compatibility issues exist, use System.Int32. For situations where System.Int32 is not large enough to hold the values, use System.Int64. If backward compatibility requires a smaller data type, use System.Byte or System.Int16.

Example

#pragma warning disable CA1028
// The code that's violating the rule is on this line.
#pragma warning restore CA1028

When to suppress

Suppress a warning from this rule only if backward compatibility issues require it. In applications, failure to comply with this rule usually does not cause problems. In libraries, where language interoperability is required, failure to comply with this rule might adversely affect your users.

Group results
0 yes 0 no
ConsensusNone (disabled)
Severity preference (yes voters)
Suggestion0
Warning0
Error0