[Flags] 属性到底有什么作用? [英] What Does the [Flags] Attribute Really Do?
问题描述
应用 [Flags]
真的吗?
What does applying [Flags]
really do?
我知道它修改了 Enum.ToString
,但它还有别的作用吗?(例如,不同的编译器或运行时行为等)
I know it modifies the behavior of Enum.ToString
, but does it do anything else? (e.g. Different compiler or runtime behavior, etc.)
编辑:是的,我知道它记录一个事实,即枚举旨在用作按位标志,并且应用它更合乎逻辑位标志.不过,我更多的是询问具体的行为变化,而不是一般的编程实践.
Edit: Yeah, I'm aware that it documents the fact that the enum is intended to be used as bitwise flags, and that it's more logical to apply it to bit flags. I was asking more about concrete behavior changes though, not general programming practices.
推荐答案
来自 MSDN 文章:
有趣的是,当Flags 被指定,Parse 和 Format方法具有高级功能.
It is interesting to note that when Flags is specified, Parse and Format methods feature advanced capabilities.
同样,Parse 方法可以成功解析逗号分隔像刚才显示的那样的字符串正确的数值.
Likewise, the Parse method can successfully parse a comma-separated string like the one just shown into the proper numeric value.
这篇关于[Flags] 属性到底有什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!