开发者

Why use int in enum declaration?

开发者 https://www.devze.com 2022-12-26 05:16 出处:网络
What\'s the point of using : int in the enum declaration as following? public enum AAType : int { Folder = 0,

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

public enum AAType : int
{
    Folder = 0,    
    File = 1, 开发者_如何学运维  
    Link = 2
}


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.


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.


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).

0

精彩评论

暂无评论...
验证码 换一张
取 消