61 lines
1.1 KiB
Plaintext
61 lines
1.1 KiB
Plaintext
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,vbnet,diff-id=1,diff-type=noncompliant]
|
|
----
|
|
<Flags()>
|
|
Enum FruitType ' Non-Compliant
|
|
None
|
|
Banana
|
|
Orange
|
|
Strawberry
|
|
End Enum
|
|
|
|
Module Module1
|
|
Sub Main()
|
|
Dim bananaAndStrawberry = FruitType.Banana Or FruitType.Strawberry
|
|
Console.WriteLine(bananaAndStrawberry.ToString()) ' Will display only "Strawberry"
|
|
End Sub
|
|
End Module
|
|
----
|
|
|
|
|
|
==== Compliant solution
|
|
|
|
[source,vbnet,diff-id=1,diff-type=compliant]
|
|
----
|
|
<Flags()>
|
|
Enum FruitType ' Compliant
|
|
None = 0
|
|
Banana = 1
|
|
Orange = 2
|
|
Strawberry = 4
|
|
End Enum
|
|
|
|
Module Module1
|
|
Sub Main()
|
|
Dim bananaAndStrawberry = FruitType.Banana Or FruitType.Strawberry
|
|
Console.WriteLine(bananaAndStrawberry.ToString()) ' Will display "Banana, Strawberry"
|
|
End Sub
|
|
End Module
|
|
----
|
|
|
|
include::../resources.adoc[]
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
include::../message.adoc[]
|
|
|
|
endif::env-github,rspecator-view[]
|