In C#, do enum flags have to be sequential? or can you leave gaps? and still perform bit-wise comparisons? ie, can you do the following:
[Flags]
public enum MyEnum
{
None = 0,
IsStarred = 1,
IsDone = 128
}
The C do while statement creates a structured loop that executes as long as a specified condition is true at the end of each pass through the loop.
The do/while loop is a variant of the while loop. This loop will execute the code block once, before checking if the condition is true, then it will repeat the loop as long as the condition is true.
What is a do-while loop? The do-while loop is very similar to that of the while loop. But the only difference is that this loop checks for the conditions available after we check a statement. Thus, it is an example of a type of Exit Control Loop.
There is nothing that requires them to be sequential.
Your enum definition is fine and will compile without issue.
The issue of readability and the principle of least astonishment, however have been greatly compromised...
There is nothing wrong with the code you have posted. This is absolutely fine:
[Flags]
public enum MyEnum
{
None = 0,
IsStarred = 1,
IsDone = 128
}
And so is this:
[Flags]
public enum MyEnum
{
IsStarred = 1,
IsDone = 128
None = 0,
SomethingElse = 4,
}
Just remember that the FlagsAttribute
does not enforce your values to be bit masks.
No such requirement. What you have is fine, assuming you capitalize [Flags]
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With