为什么在枚举声明中使用 int ?
在下面的枚举声明中使用 : int 有什么意义?
public enum AAType : int
{
Folder = 0,
File = 1,
Link = 2
}
What's the point of using : int in the enum declaration as following?
public enum AAType : int
{
Folder = 0,
File = 1,
Link = 2
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
事实上,Enum 是一个专门的 Int,您可以对每个 Enum 值使用字节(Apple = 1、Pear = 2、Orange = 4),然后您可以在 Piped 中传递 Enum 并根据字节值确定要执行的操作(查看Reflection.BindingFlags等)。
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).
enum
的默认基础类型是int
,因此通过显式指定它,您(也许)只会获得清晰度,但其行为与相同: int
被省略。The default underlying type of an
enum
isint
, so by specifying it explicitly you only (perhaps) gain in clarity, but the behavior's just the same as if: int
was omitted.enum
的默认支持类型是int
。您可以将支持类型更改为其他类型,例如short
或long
。指定 int 可能只是为了清楚起见。The default backing type of
enum
isint
. You can change the backing type to something else, likeshort
orlong
. Specifyingint
is probably just for clarity.