Recall & Review
beginner
What is an enum in C#?
An enum (short for enumeration) is a special data type that lets you define a set of named constant values. It helps group related constants under one type for better readability and type safety.
Click to reveal answer
beginner
What are constants in C#?
Constants are fixed values declared with the keyword
const. They cannot change during program execution and are usually used for single fixed values like numbers or strings.Click to reveal answer
intermediate
When should you use an enum instead of constants?
Use enums when you have a group of related named values that represent a category or set of options. Enums improve code clarity and help prevent invalid values by restricting inputs to the defined set.
Click to reveal answer
intermediate
When are constants preferred over enums?
Use constants when you need a single fixed value or unrelated fixed values. Constants are simpler and better for values like mathematical constants or configuration strings.
Click to reveal answer
intermediate
What is a key advantage of enums over constants?
Enums provide type safety, meaning the compiler can check if you use only valid values from the enum. Constants do not provide this safety since they are just individual values.
Click to reveal answer
Which of the following is true about enums in C#?
✗ Incorrect
Enums group related named constants and provide type safety. Their values cannot change at runtime.
When should you use a constant instead of an enum?
✗ Incorrect
Constants are best for single fixed values like Pi or configuration strings.
What keyword is used to declare a constant in C#?
✗ Incorrect
The
const keyword declares a constant value in C#.Which feature is a benefit of enums over constants?
✗ Incorrect
Enums provide type safety by restricting values to the defined set.
Can enums be used in switch statements in C#?
✗ Incorrect
Enums are commonly used in switch statements to handle different cases clearly.
Explain when you would choose an enum over constants in C# and why.
Think about grouping and safety.
You got /4 concepts.
Describe a scenario where constants are better than enums and explain your reasoning.
Consider simple fixed values like Pi.
You got /4 concepts.