0
0
C Sharp (C#)programming~10 mins

Enum vs constants decision in C Sharp (C#) - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare an enum named Color with values Red, Green, and Blue.

C Sharp (C#)
public enum Color [1] Red, Green, Blue };
Drag options to blanks, or click blank then click option'
A(
B{
C[
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses instead of curly braces.
Using square brackets or angle brackets.
2fill in blank
medium

Complete the code to declare a constant integer named MaxValue with value 100.

C Sharp (C#)
public const int MaxValue = [1];
Drag options to blanks, or click blank then click option'
A100
Bmax
C"100"
DMaxValue
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string "100" instead of number 100.
Using variable names instead of values.
3fill in blank
hard

Fix the error in the code to correctly assign the enum value Color.Green to variable selectedColor.

C Sharp (C#)
Color selectedColor = [1];
Drag options to blanks, or click blank then click option'
AGreen
BselectedColor.Green
CColor.Green
DColor[Green]
Attempts:
3 left
💡 Hint
Common Mistakes
Using only the member name without enum type.
Trying to access enum members like an array.
4fill in blank
hard

Fill both blanks to declare a constant string named Status with value "Active".

C Sharp (C#)
public const [1] Status = [2];
Drag options to blanks, or click blank then click option'
Astring
B"Active"
CActive
Dint
Attempts:
3 left
💡 Hint
Common Mistakes
Using unquoted text for string constants.
Using wrong type like int for string values.
5fill in blank
hard

Fill all three blanks to create a dictionary mapping enum Color to string names, including only Red and Blue.

C Sharp (C#)
var colorNames = new Dictionary<Color, [1]> { {Color.Red, [2], {Color.Blue, [3] };
Drag options to blanks, or click blank then click option'
Astring
B"Red"
C"Blue"
Dint
Attempts:
3 left
💡 Hint
Common Mistakes
Using int instead of string as dictionary value type.
Not quoting string values.