Click to See Complete Forum and Search --> : Flags enumeration question.


MikeB
July 25th, 2007, 08:55 AM
I have a Unit class, where an object can support one or more formats.

[Flags()]
enum Format { Decimal = 1, Engineering = 2, Architectural = 4, Fractional = 8 };

The "Feet" units can support anyone of those formats:

Eg.: 1.5 feet can be seen as Decimal (1.5), Engineering (1'-6.0"),
Architectural (1'-6"), or Fractional (1 1/2).

In my class I have to variables

private Format _formats; // Supported formats
private Format _default; // Default format


How can I ensure that if the default is set, it can be set to only 1 flag value?

Mike B

MadHatter
July 25th, 2007, 04:41 PM
you cant restrict it. you can make it a const value which will keep you from assigning it outside of its initializer.

private const Format _default = Format.Decimal;