Difficulty: Easy
Correct Answer: Since 500, 1000, 1500 exceed the valid range of byte, the compiler will report an error.
Explanation:
Introduction / Context:
In C#, an enum’s underlying type controls the representable range of its named constants. This question checks if you remember that constraint.
Given Data / Assumptions:
byte
(range 0..255).
Concept / Approach:
Enum members must be compile-time constants convertible to the underlying type without overflow. Assigning a value outside the underlying type’s range is a compile-time error.
Step-by-Step Solution:
byte
.Compiler emits an error for each out-of-range assignment.
Verification / Alternative check:
Change the underlying type to int
or reduce constants to within 0..255 to make it compile.
Why Other Options Are Wrong:
(a) is false — you can assign compatible constants; (b) successive values are not required; (d) underlying type can be any integral type except char
by default (int if unspecified); (e) access modifiers on enum members are not used — they are constants.
Common Pitfalls:
Assuming the compiler silently wraps values; it does not for enum member declarations.
Final Answer:
Since 500, 1000, 1500 exceed the valid range of byte, the compiler will report an error.
Discussion & Comments