开发者

C# int to Flag Enum [duplicate]

开发者 https://www.devze.com 2023-04-11 06:42 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: C# int to enum conversion
This question already has answers here: Closed 11 years ago.

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!


Yes.

That works just fine. Flags attribute or not.

0

精彩评论

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

关注公众号