0
0
C Sharp (C#)programming~20 mins

Enum declaration syntax in C Sharp (C#) - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Enum Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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);
    }
}
A0
B2
C3
D4
Attempts:
2 left
💡 Hint
Remember enums start numbering from 0 by default.
Predict Output
intermediate
2: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);
    }
}
A5
B10
C1
D0
Attempts:
2 left
💡 Hint
Check the assigned value for Active.
Predict Output
advanced
2: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() {}
}
ACompile-time error: Enum values must be unique
BRuntime error: Duplicate enum member
CNo error, compiles successfully
DCompile-time error: Duplicate enum member name
Attempts:
2 left
💡 Hint
Check if enum member names can repeat.
Predict Output
advanced
2: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);
    }
}
ARead, Write
B3
CRead Write
D1, 2
Attempts:
2 left
💡 Hint
The [Flags] attribute changes how the enum prints combined values.
🧠 Conceptual
expert
3:00remaining
Which enum declaration is valid and assigns correct values?
Which of these enum declarations compiles without error and assigns the values as shown?
Aenum Levels { Low = 1, Medium = 2, High = 5, Critical = 5 } // Duplicate value 5
Benum Levels { Low = 1, Medium, High = 5, Critical } // Low=1, Medium=2, High=5, Critical=6
Cenum Levels { Low, Medium = 2, High, Critical } // Low=0, Medium=2, High=3, Critical=4
Denum Levels { Low = 1, Medium = 2, High, Critical = 2 } // Duplicate value 2
Attempts:
2 left
💡 Hint
Check how enum values increment when not explicitly assigned.