A
Anders Borum
Hello!
Consider the following enumeration used to combine several of the values. I
am trying to figure out what the best solution is to check for the presence
of a value using bitwise comparisons. I'm able to get if statements to work,
but am unsure if switch statemens allow this.
Maybe it's just me on a friday, but if you've got a better solution than if
statements, please let me know.
[Flags()]
enum position
{
first = 1,
second = 2,
third = 4,
last = 8
}
...
// Create variable with two values from the enumeration
position p = position.first | position.second;
switch (p)
{
case position.first: { .. }
case position.second: { .. }
}
// The following if statement works
if ((p & position.first) > 0) { .. }
// The following if statement also works
if ((p & position.first) == position.first) { .. }
Thanks in advance.
Consider the following enumeration used to combine several of the values. I
am trying to figure out what the best solution is to check for the presence
of a value using bitwise comparisons. I'm able to get if statements to work,
but am unsure if switch statemens allow this.
Maybe it's just me on a friday, but if you've got a better solution than if
statements, please let me know.
[Flags()]
enum position
{
first = 1,
second = 2,
third = 4,
last = 8
}
...
// Create variable with two values from the enumeration
position p = position.first | position.second;
switch (p)
{
case position.first: { .. }
case position.second: { .. }
}
// The following if statement works
if ((p & position.first) > 0) { .. }
// The following if statement also works
if ((p & position.first) == position.first) { .. }
Thanks in advance.