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 }

Difficulty: Easy

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.

Discussion & Comments

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