c# - How to store several states in one variable? -
There are several binary states in my object items
which can be combined
Bull cannabosed; Bull Canbach; Bull canback exclaimed;
I need to store the current combination of values in one variable. The reason is that I need to store this value in DB. In C ++, I will make a bit-mask where there will be a small stake in a state. Is this a good practice. NET?
You can use an enumeration with the flag
attribute:
state = mystates. Kenbus Soul | MyStates.CanBeExchanged
Note that this only works when the enum value powers two (as explained in a comment), so that they can be easily added and when one More people than are set to not overlap.
You can also define prices as a combination of several other values:
CanBeSoldOrBought = CanBeSold | Canbebought
or
CanBeSoldOrBought = 3
This file permits to work as expected Can be seen as an example, where ReadWrite is usually a combination of reading and compose bits.
And yes, this is a common practice that framework itself uses it in many places.
The usual way of check for a particular set of sets is then
((State and Mistakes. Kanbis)! = 0) { ...}
Comments
Post a Comment