tags:

views:

144

answers:

3

What's the point of using : int in the enum declaration as following?

public enum AAType : int
{
    Folder = 0,    
    File = 1,   
    Link = 2
}
+7  A: 

The default underlying type of an enum is int, so by specifying it explicitly you only (perhaps) gain in clarity, but the behavior's just the same as if : int was omitted.

Alex Martelli
+4  A: 

The default backing type of enum is int. You can change the backing type to something else, like short or long. Specifying int is probably just for clarity.

Matt Olenik
is there any other data type that can be the backing type of enum?
Carlos_Liu
Any of the integral types (http://msdn.microsoft.com/en-us/library/exx3b86w(v=VS.80).aspx) except char
Matt Olenik
A: 

The fact that an Enum is a specialized Int you can use bytes for each Enum value (Apple = 1, Pear = 2, Orange = 4) and then you can pass the Enums in Piped and determine what to do based on the byte value (look at Reflection.BindingFlags, etc).

Dan
You can implement flags (which is what I think you're trying to describe) using backing types other than int.
Michael Petrotta