include::../description.adoc[]

== How to fix it

Define enumeration constants in powers of two, that is, 1, 2, 4, 8, and so on.

=== Code examples

==== Noncompliant code example

[source,csharp,diff-id=1,diff-type=noncompliant]
----
var bananaAndStrawberry = FruitType.Banana | FruitType.Strawberry; 
Console.WriteLine(bananaAndStrawberry.ToString());  // Will display only "Strawberry"

[Flags]
enum FruitType    // Noncompliant
{
  None,
  Banana,
  Orange,
  Strawberry
}
----

==== Compliant solution

[source,csharp,diff-id=1,diff-type=compliant]
----
var bananaAndStrawberry = FruitType.Banana | FruitType.Strawberry;
Console.WriteLine(bananaAndStrawberry.ToString()); // Will display "Banana, Strawberry"

[Flags]
enum FruitType
{
  None = 0,
  Banana = 1,
  Orange = 2,
  Strawberry = 4
}


----

include::../resources.adoc[]

ifdef::env-github,rspecator-view[]

'''
== Implementation Specification
(visible only on this page)

include::../message.adoc[]

endif::env-github,rspecator-view[]
