Recall & Review
beginner
What is an enum in C#?
An enum (short for enumeration) is a special data type that lets you define a group of named constant values. It helps make code more readable by using names instead of numbers.
Click to reveal answer
beginner
How do you declare a simple enum in C#?
Use the
enum keyword followed by the enum name and a list of named values inside curly braces. For example:<br>enum Days { Sunday, Monday, Tuesday }Click to reveal answer
intermediate
Can you assign specific integer values to enum members in C#?
Yes, you can assign specific integer values to enum members by using the equals sign. For example:<br>
enum Days { Sunday = 1, Monday = 2, Tuesday = 3 }Click to reveal answer
intermediate
What is the default underlying type of an enum in C#?
The default underlying type of an enum in C# is
int. This means each enum member is stored as an integer unless you specify a different type.Click to reveal answer
advanced
How do you specify a different underlying type for an enum in C#?
You specify the underlying type by adding a colon and the type name after the enum name. For example:<br>
enum Days : byte { Sunday, Monday, Tuesday } This makes the enum use byte instead of int.Click to reveal answer
Which keyword is used to declare an enum in C#?
✗ Incorrect
The
enum keyword is used to declare an enumeration type in C#.What is the default underlying type of an enum in C#?
✗ Incorrect
By default, enums use
int as their underlying type.How do you assign a specific integer value to an enum member?
✗ Incorrect
You assign values using an equals sign, like
Sunday = 1.Which of these is a valid enum declaration with a specified underlying type?
✗ Incorrect
The correct syntax to specify the underlying type is with a colon, like
enum Colors : byte.What will be the integer value of the first member if you don't assign values explicitly?
✗ Incorrect
By default, the first enum member has the value 0, and the rest increment by 1.
Explain how to declare an enum in C# and how to assign specific values to its members.
Think about the basic syntax and how to set numbers for each name.
You got /4 concepts.
Describe the default underlying type of enums in C# and how to change it.
Remember the colon syntax after the enum name.
You got /3 concepts.