Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flags enum with too many items; last value is too large. How can I resolve this? [duplicate]

Tags:

c#

enums

flags

Possible Duplicate:
When you use flag(Enum) you have a limit of 64. What are the alternative when you reach the limit?

I have the following [Flags] enum that has to contain 33 elements:

[Flags]
public enum Types
{
    None = 0,
    Alarm = 1,
    Exit = 2,
    Panic = 4,
    Fire = 8,
    Tamper = 16,
    Key = 32,
    Line = 64,
    FTC = 128,
    Unused = 256,
    tech_1 = 512,
    //... tech_2 through _7 omitted for brevity
    tech_8 = 65536,
    fire_1 = 131072,
    //... fire_2 through _11 omitted for brevity
    fire_12 = 268435456,
    Key = 536870912,
    Exit = 1073741824,
    Gas = 2147483648, // Cannot convert source type uint to target type int
}

The value for the last item appears to be too large. Has anyone dealt with this before? Any ideas how this can be resolved / worked around?

like image 556
DaveDev Avatar asked Apr 20 '12 09:04

DaveDev


1 Answers

You can specify the type of the enum to be something with a greater range.

[Flags]
public enum Types : long
like image 73
Jeff Foster Avatar answered Oct 18 '22 13:10

Jeff Foster