C#

C#

By DeepSource

`enum` with `Flags` attribute has invalid valuesCS-W1015

Bug risk

Flags attribute is used to indicate that an enumeration can be treated as a bit field; that is, a set of flags. For this to be possible, the values specified inside the enum must be a power of 2. Either consider providing the right values, or dropping the said enum's attribute altogether.

Examples

Bad Practice

[Flags]
enum Permissions
{
    Read = 1,
    Write = 3 // Wrong
};

Recommended

[Flags]
enum Permissions
{
    Read = 1,
    Write = 2
};

Reference