Recall & Review
beginner
What are underlying numeric values in C# enums?
Underlying numeric values are the integer values automatically or explicitly assigned to each enum member. By default, they start at 0 and increase by 1 for each member.
Click to reveal answer
beginner
How can you specify a custom underlying numeric value for an enum member in C#?
You assign a value directly to the enum member, for example:
enum Days { Sunday = 1, Monday = 2 }.Click to reveal answer
beginner
What is the default underlying type of an enum in C#?
The default underlying type of an enum in C# is
int.Click to reveal answer
intermediate
Can you change the underlying type of an enum in C#? If yes, how?
Yes, you can specify a different integral type like
byte, short, long by declaring it after the enum name, e.g., enum Colors : byte { Red, Green }.Click to reveal answer
beginner
How do you get the underlying numeric value of an enum member in C#?
You can cast the enum member to its underlying type, for example:
int value = (int)Days.Monday;.Click to reveal answer
What is the default underlying numeric value of the first enum member if not specified?
✗ Incorrect
By default, the first enum member has the underlying value 0.
How do you specify an enum with an underlying type of byte?
✗ Incorrect
The syntax to specify the underlying type is
enum Name : type { ... }.What happens if you assign the same numeric value to two enum members?
✗ Incorrect
Enum members can share the same underlying value without error.
How do you retrieve the numeric value of an enum member in C#?
✗ Incorrect
Casting the enum member to its underlying type returns its numeric value.
Which of these is NOT a valid underlying type for an enum in C#?
✗ Incorrect
Enums can only have integral underlying types, not string.
Explain what underlying numeric values are in C# enums and how they are assigned.
Think about how enum members get their numbers.
You got /3 concepts.
Describe how to change the underlying type of an enum and why you might want to do that.
Look at the enum declaration syntax.
You got /3 concepts.