Represents a type that is a universal enumeration type. All enumeration types derive from this type.
The System.Enum
class is an abstract base class from which all enumeration types inherit.
It provides methods for working with enumeration types, such as retrieving their names, values, and attributes.
Enumerations provide a convenient way to define a set of named constants.
public abstract class Enum : ValueType, IComparable, IConvertible, IEquatable<Enum>
Enumeration types in .NET are value types that inherit from System.Enum
.
They are used to create a set of named constants that represent a set of discrete values.
For example, you can define an enumeration for days of the week:
public enum DayOfWeek
{
Sunday,
Monday,
Tuesday,
Wednesday,
Thursday,
Friday,
Saturday
}
The underlying type of an enumeration can be any integral numeric type (byte
, sbyte
, short
, ushort
, int
, uint
, long
, or ulong
).
If not specified, the underlying type is int
.
The System.Enum
class itself is abstract and cannot be instantiated directly.
You interact with enumeration types through the static methods provided by the System.Enum
class or by casting to the specific enumeration type.
System.Enum
does not declare any public fields.
System.Enum
does not declare any public properties.
System.Enum
is an abstract class and therefore does not have a struct layout.
System.Object
System.ValueType
System.Enum
Interfaces implemented by System.Enum
:
System.Enum
is the base class for all enumeration types in .NET.
Every enumeration type implicitly implements this class.
Examples include: