What the Heck is an ENUM?

In my latest post Explore your [Environment] I said the following:

PS> [System.Environment+SpecialFolder]

IsPublic IsSerial Name                                     BaseType
——– ——– —-                                     ——–
False    True     SpecialFolder                            System.Enum

Notice that it is an ENUM.  The great things about ENUMS is that when you specify an invalid value – it tells you what the valid values are:

One of the comments made me realize that a lot of people will have no idea what I’m talking about so I thought I would spend a minute explaining. 

ENUM is short for ENUMERATION.  In .NET, ENUM is a base class for a set of named constants.  You can think of it as a set of strings (that is not entirely accurate but for our purposes – it is a perfect explanation.   So when you see that something takes an ENUM, what it means is that it doesn’t just take any old string – it takes one of a set of strings. 

What is that set of string? – That’s the beauty of an ENUM, it will tell it.  All you have to do is to provide a wrong value and it will tell you what the right values are.

Enjoy

Jeffrey Snover [MSFT]
Windows Management Partner Architect
Visit the Windows PowerShell Team blog at:    http://blogs.msdn.com/PowerShell
Visit the Windows PowerShell ScriptCenter at:  http://www.microsoft.com/technet/scriptcenter/hubs/msh.mspx