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

Underlying numeric values in C Sharp (C#) - Interactive Code 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.

C Sharp (C#)
[1] Color { Red, Green, Blue }
Drag options to blanks, or click blank then click option'
Aclass
Benum
Cstruct
Dinterface
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'class' instead of 'enum' to declare an enumeration.
2fill in blank
medium

Complete the code to get the underlying numeric value of the enum member.

C Sharp (C#)
int value = (int)Color.[1];
Drag options to blanks, or click blank then click option'
ARed
BYellow
CPurple
DOrange
Attempts:
3 left
💡 Hint
Common Mistakes
Using a member name that does not exist in the enum.
3fill in blank
hard

Fix the error in the code to correctly cast the enum to its underlying value.

C Sharp (C#)
var number = [1]Color.Green;
Drag options to blanks, or click blank then click option'
A(int)
B(double)
C(string)
D(bool)
Attempts:
3 left
💡 Hint
Common Mistakes
Casting enum to a non-numeric type like string or bool.
4fill in blank
hard

Fill both blanks to create a dictionary mapping enum members to their numeric values.

C Sharp (C#)
var dict = new Dictionary<Color, int> { [1], [2] };
Drag options to blanks, or click blank then click option'
A{Color.Red, (int)Color.Red}
B{Color.Yellow, (int)Color.Yellow}
C{Color.Green, (int)Color.Green}
D{Color.Blue, (int)Color.Blue}
Attempts:
3 left
💡 Hint
Common Mistakes
Using enum members that do not exist.
Not casting enum members to int for values.
5fill in blank
hard

Fill all three blanks to create a LINQ expression mapping enum members to their numeric values if the value is greater than 0.

C Sharp (C#)
var result = Enum.GetValues(typeof(Color)).Cast<Color>().Where([3] => (int)[3] > 0).ToDictionary([1] => [1], [1] => [2]);
Drag options to blanks, or click blank then click option'
Acolor
B(int)color
CColor
Dvar
Attempts:
3 left
💡 Hint
Common Mistakes
Using the enum type name instead of a variable in the loop.
Not casting the enum member to int for the value.