C#.NET enums: which underlying datatype is <em>not</em> permitted for an enum?

Difficulty: Easy

Correct Answer: float

Explanation:


Introduction / Context:
This question verifies your knowledge of which underlying types are valid for C#.NET enums. Picking an invalid type demonstrates understanding of the integral-only rule.



Given Data / Assumptions:

  • Options include integral types and a floating-point type.
  • Enums in C# require an underlying integral type.


Concept / Approach:
In C#, an enum's underlying type must be one of: byte, sbyte, short, ushort, int, uint, long, or ulong. Floating-point (float, double) and decimal are not allowed.



Step-by-Step Reasoning:

Check each candidate:byte → valid.short → valid.float → invalid (not integral).int → valid and is the default when unspecified.


Verification / Alternative check:
Attempt enum E : float { A } in a test project; the compiler reports that the underlying type must be an integral type.



Why Other Options Are Wrong:
They list integral types that are explicitly allowed by the language specification.



Common Pitfalls:
Assuming any numeric type is acceptable or thinking that decimal/float work because they are “numbers.” Enums are intended to map names to discrete integral constants.



Final Answer:
float

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion