Challenge - 5 Problems
Enum Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this enum usage?
Consider this C# code snippet. What will be printed when it runs?
C Sharp (C#)
enum Days { Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday } class Program { static void Main() { Days today = Days.Wednesday; Console.WriteLine((int)today); } }
Attempts:
2 left
💡 Hint
Remember enums start numbering from 0 by default.
✗ Incorrect
By default, the first enum member has the value 0, so Sunday=0, Monday=1, Tuesday=2, Wednesday=3. Casting Wednesday to int prints 3.
❓ Predict Output
intermediate2:00remaining
What is the output of this enum with custom values?
Look at this enum with assigned values. What does the program print?
C Sharp (C#)
enum Status { Pending = 1, Active = 5, Closed = 10 } class Program { static void Main() { Status s = Status.Active; Console.WriteLine((int)s); } }
Attempts:
2 left
💡 Hint
Check the assigned value for Active.
✗ Incorrect
Active is explicitly assigned the value 5, so casting it to int prints 5.
❓ Predict Output
advanced2:00remaining
What error does this enum declaration cause?
What error will this code produce when compiled?
C Sharp (C#)
enum Colors { Red, Green = 5, Blue, Green = 10 } class Program { static void Main() {} }
Attempts:
2 left
💡 Hint
Check if enum member names can repeat.
✗ Incorrect
Enum member names must be unique. Declaring 'Green' twice causes a compile-time error.
❓ Predict Output
advanced2:00remaining
What is the output of this enum with flags attribute?
Given this code using [Flags], what will be printed?
C Sharp (C#)
[Flags] enum Permissions { None = 0, Read = 1, Write = 2, Execute = 4 } class Program { static void Main() { Permissions p = Permissions.Read | Permissions.Write; Console.WriteLine(p); } }
Attempts:
2 left
💡 Hint
The [Flags] attribute changes how the enum prints combined values.
✗ Incorrect
With [Flags], combined enum values print as a comma-separated list of names.
🧠 Conceptual
expert3:00remaining
Which enum declaration is valid and assigns correct values?
Which of these enum declarations compiles without error and assigns the values as shown?
Attempts:
2 left
💡 Hint
Check how enum values increment when not explicitly assigned.
✗ Incorrect
Option B is valid: Medium gets 2 automatically after Low=1; Critical gets 6 after High=5. Duplicate values are allowed but not in options B and D as stated.