I have the following enums defined in my code:
[Flags]
public enum Symbol
{
A,
B,
}
public enum Production
{
AA = Symbol.A | Symbol.A,
AB = Symbol.A | Symbol.B,
BA = Symbol.B | Symbol.A, // <- this will obviously not work
}
I was planning to make use of enums
as they eventually would prevent unwanted Symbols
to be used for Productions
. The problem is that the following code does not produce the output that I'm after:
Productions product1 = (Productions) (Symbol.A | Symbol.A); // Production.AA
Productions product2 = (Productions) (Symbol.A | Symbol.B); // Production.AB
Productions product3 = (Productions) (Symbol.B | Symbol.A); // Production.AB (and not Production.BA as I would like)
I completely understand why this is happening, but was wondering if there is a combination of bitwise operators that I could use to make it work as I originally intended?
Or maybe in general I'm trying to use enums in a incorrect way, therefore should switch to chars
or even custom structs?