Skip to main content This browser is no longer supported. Show
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support. Enumeration types (C# reference)
In this articleAn enumeration
type (or enum type) is a value type defined by a set of named constants of the underlying integral numeric type. To define an enumeration type, use the
By default, the associated constant values of enum members are of type
You cannot define a method inside the definition of an enumeration type. To add functionality to an enumeration type, create an extension method. The default value of an enumeration type You use an enumeration type to represent a choice from a set of mutually exclusive values or a combination of choices. To represent a combination of choices, define an enumeration type as bit flags. Enumeration types as bit flagsIf you want an enumeration type to represent a combination of choices, define enum members for those choices such that an individual
choice is a bit field. That is, the associated values of those enum members should be the powers of two. Then, you can use the bitwise logical operators
For more information and examples, see the System.FlagsAttribute API reference page and the Non-exclusive members and the Flags attribute section of the System.Enum API reference page. The System.Enum type and enum constraintThe System.Enum type is the abstract base class of all enumeration types. It provides a number of methods to get information about an enumeration type and its values. For more information and examples, see the System.Enum API reference page. You can use ConversionsFor any enumeration type, there exist explicit conversions between the enumeration type and its underlying integral type. If you cast an enum value to its underlying type, the result is the associated integral value of an enum member.
Use the Enum.IsDefined method to determine whether an enumeration type contains an enum member with the certain associated value. For any enumeration type, there exist boxing and unboxing conversions to and from the System.Enum type, respectively. C# language specificationFor more information, see the following sections of the C# language specification:
See also
FeedbackSubmit and view feedback for Which of the following is a database on the local system that stores user account information?The Security Account Manager (SAM) is a database that is present on computers running Windows operating systems that stores user accounts and security descriptors for users on the local computer.
Which of the following involves overwriting all of the information on a drive?Drive wiping: This is the act of overwriting all information on a drive. Drive wiping, which is covered in National Institute of Standards and Technology (NIST) 800-88 and U.S. Department of Defense (DoD) 5200.28, allows a drive to be reused.
Which of the following ports does ssh operate on?An SSH server, by default, listens on the standard Transmission Control Protocol (TCP) port 22.
What is it called when you obtain administrative privileges from a normal user account?What is it called when you obtain administrative privileges from a normal user account? Privilege escalation.
|