Underlying type
Context: Enums have an underlying integral type (default is int). You can change it to byte, sbyte, short, ushort, int, uint, long, or ulong.
public enum SmallEnum : byte{ Zero = 0, One = 1, Max = 255}Specifying underlying type
Section titled “Specifying underlying type”public enum FileMode : uint{ Read = 1, Write = 2, ReadWrite = 3}Real-world usage example
Section titled “Real-world usage example”Memory‑sensitive applications: Use byte as underlying type for enums with less than 256 values to save memory when stored in large arrays.
Example: In game development, a WeaponType : byte enum reduces memory footprint for thousands of enemies. Enum.GetUnderlyingType can be used to inspect.