C#.NET Enums — determine what happens when enum members are initialized with variables. Given: int a = 10; int b = 20; int c = 30; enum color : byte { red = a, green = b, blue = c }
C# Programming
Enumerations
Difficulty: Easy
Choose an option
-
AVariables cannot be assigned to enum elements.
-
BVariables can be assigned to any one of the enum elements.
-
CVariables can be assigned only to the first enum element.
-
DValues assigned to enum elements must always be successive values.
-
EValues assigned to enum elements must always begin with 0.
Answer
Correct Answer: Variables cannot be assigned to enum elements.
Explanation
Introduction / Context:Enum member initializers in C#.NET must be compile-time constants. Variables cannot be used directly.
Step-by-Step:
1) a, b, c are variables, not constants.2) Compiler requires const expressions for enum members.3) Declaring them const fixes the error.Final Answer:Variables cannot be assigned to enum elements.