enum) is a distinct value type defined by a set of named integral constants. At runtime, an enum is resolved to its underlying numeric type, meaning it carries the same memory footprint and performance characteristics as a standard primitive integer. All enums implicitly inherit from the abstract class System.Enum, which in turn inherits from System.ValueType.
Syntax and Initialization
By default, the underlying type of an enum isint. The first enumerator has the value 0, and the value of each successive enumerator is incremented by 1.
Underlying Types
An enum can be declared with any integral numeric type exceptchar. Supported types are byte, sbyte, short, ushort, int, uint, long, and ulong. The C# specification requires enum underlying types to have a deterministic size for memory layout and interop, which is why architecture-dependent types like nint and nuint are not permitted. Specifying a smaller underlying type reduces the memory footprint of the struct or class containing the enum.
Type Conversion
Because enums are strongly typed, implicit conversions between anenum and its underlying integral type are generally not allowed, requiring explicit casting. The sole exception is the decimal integer literal 0, which the C# specification permits to be implicitly converted to any enum type.
Bitwise Enumerations ([Flags])
The [Flags] attribute indicates that an enumeration can be treated as a bit field. This allows a single enum variable to store multiple values simultaneously using bitwise operations. When defining a flags enum, values must be powers of two (using bit shift operators is standard practice).
|, &, ~, ^) and the HasFlag method are used to manipulate and evaluate flag combinations.
Core System.Enum Methods
The System.Enum base class provides static methods for reflection, parsing, and manipulation of enum types.
Parsing Strings to Enums:
Tired of Poor C# Skills? Fix That With Deep Grasping!Learn More





