Given the following enum flag
[Flags]
public enum Options : long
{
None = 0,
One = 1 << 0,
Two = 1 << 1,
Three = 1 << 2,
Four = 1 << 3
}
I can create a variable representing a combination of Options
and this is represented by a numeric value under the covers (in this case 13
)
var oneThreeAndFour = Options.One | Options.Three | Options.Four;
Console.WriteLine(oneThreeAndFour); // One, Three, Four
Console.WriteLine((long) oneThreeAndFour); // 13
I can also convert from the numeric value (in this case 13
) back to then combination of Options
Console.WriteLine((Options) 13); // One, Three, Four
My question is how is this conversion happening under the covers? How does .net know that 13
represents One, Three, Four
?
The reason I ask is I'm trying the build an equivalent based on a BigInteger
that will allow more than 64 values.
The example here:
https://stackoverflow.com/a/38557486 works by storing / parsing the actual string value (One, Three, Four
) but I would prefer to store / parse the underlying BigInteger
value instead.