Defining an enumeration
An enumeration is a set of named constants. .NET is full of examples of enumerations. For example, the System.Security.AccessControl.FileSystemRights
enumeration describes all of the numeric values that are used to define access rights for files or directories.
Enumerations are also used by PowerShell itself. For example, System.Management.Automation.ActionPreference
contains the values for the preference variables, such as ErrorActionPreference
and DebugPreference
.
You create enumerations by using the enum
keyword followed by a list of names and values:
enum MyEnum {
First = 1
Second = 2
Third = 3
}
Each name must be unique within the enumeration and must start with a letter or an underscore. The name may contain numbers after the first character. The name cannot be quoted and cannot contain the hyphen character.
The value does not have to be unique. One or more names in an enumeration can share a single value:
...