C# int 到 Flag Enum

发布于 2024-12-08 20:38:28 字数 512 浏览 4 评论 0原文

可能的重复:
C# int 到 enum 转换

是否可以以某种方式将 int 转换为标志组合枚举?那么,是否

[Flags]
public enum Foo {a = 0x80,
                 b = 0x40,
                 c = ...,
                 ...
                 h = 0x1,
                 i = 0};

可以(或以某种方式可能)使

Foo fooInstance = (Foo)6;

fooInstance 变为 00000110 ?

谢谢!

Possible Duplicate:
C# int to enum conversion

Is it somehow possible to convert an int to a flag combination enum? So, if

[Flags]
public enum Foo {a = 0x80,
                 b = 0x40,
                 c = ...,
                 ...
                 h = 0x1,
                 i = 0};

is it OK (or somehow possible) to do

Foo fooInstance = (Foo)6;

so that fooInstance would be 00000110?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

傲性难收 2024-12-15 20:38:28

是的。

效果很好。标记属性与否。

Yes.

That works just fine. Flags attribute or not.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文