Complete the code to define an enum with the Flags attribute.
[[1]] public enum Days { None = 0, Sunday = 1, Monday = 2 }
The Flags attribute allows an enum to be treated as a bit field, enabling bitwise operations.
Complete the code to define enum values as powers of two for bitwise combination.
public enum Permissions
{
Read = 1,
Write = [1],
Execute = 4
}Enum values for flags should be powers of two (1, 2, 4, 8, ...) to allow unique bitwise combinations.
Fix the error in combining flags using bitwise OR operator.
Permissions userPermissions = Permissions.Read [1] Permissions.Write;The bitwise OR operator | combines flags correctly by setting bits from both operands.
Fill both blanks to check if a flag is set using bitwise AND and compare to the flag.
if ((userPermissions [1] Permissions.Write) [2] Permissions.Write) { Console.WriteLine("Write permission granted."); }
To check if a flag is set, use bitwise AND '&' and compare with '==' to the flag value.
Fill all three blanks to define a Flags enum, combine flags, and check if a flag is set.
[[1]] public enum Access { None = 0, Read = 1, Write = 2 } Access accessRights = Access.Read [2] Access.Write; bool canWrite = (accessRights [3] Access.Write) == Access.Write;
The Flags attribute marks the enum for bitwise use. Combine flags with | and check flags with &.