Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# int to Flag Enum [duplicate]

Tags:

c#

enums

bitflags

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!

like image 906
john Avatar asked Oct 07 '11 18:10

john


1 Answers

Yes.

That works just fine. Flags attribute or not.

like image 132
Rangoric Avatar answered Sep 29 '22 23:09

Rangoric