This documentation is archived and is not being maintained.

Enum Storage should be Int32







Breaking Change


The underlying type of a public enumeration is not System.Int32.

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. Note that there is no significant performance gain in using a data type smaller than Int32. If you cannot use the default data type, you should use one of the CLS-compliant integral types, Byte, Int16, Int32, or Int64, to ensure that all of the enumeration's values are representable in CLS-compliant programming languages.

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

Exclude 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 negatively affect your users.

The following example shows two enumerations that do not use the recommended underlying data type.

using System;

namespace DesignLibrary
   public enum Days : uint
      None        = 0,
      Monday      = 1,
      Tuesday     = 2,
      Wednesday   = 4,
      Thursday    = 8,
      Friday      = 16,
      All         = Monday| Tuesday | Wednesday | Thursday | Friday

   public enum Color :sbyte
      None        = 0,
      Red         = 1,
      Orange      = 3,
      Yellow      = 4