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

Why enums are needed in C Sharp (C#) - Test Your Understanding

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 Days.

C Sharp (C#)
enum [1] { Sunday, Monday, Tuesday }
Drag options to blanks, or click blank then click option'
AMonths
BWeek
CDays
DColors
Attempts:
3 left
💡 Hint
Common Mistakes
Using a name unrelated to the values like Months or Colors.
Leaving the enum name blank.
2fill in blank
medium

Complete the code to assign the enum value Monday to variable today.

C Sharp (C#)
Days today = Days.[1];
Drag options to blanks, or click blank then click option'
ASunday
BMonday
CFriday
DTuesday
Attempts:
3 left
💡 Hint
Common Mistakes
Using a day not in the enum like Friday.
Using the enum name without the member.
3fill in blank
hard

Fix the error in the code to compare enum values correctly.

C Sharp (C#)
if (today == Days.[1]) { Console.WriteLine("It's Monday"); }
Drag options to blanks, or click blank then click option'
Amonday
BMon
CMONDAY
DMonday
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase or abbreviated names that don't match the enum.
Using strings instead of enum members.
4fill in blank
hard

Fill both blanks to create a switch statement that prints the day name.

C Sharp (C#)
switch (today) {
  case Days.[1]:
    Console.WriteLine("Sunday");
    break;
  case Days.[2]:
    Console.WriteLine("Monday");
    break;
}
Drag options to blanks, or click blank then click option'
ASunday
BMonday
CTuesday
DFriday
Attempts:
3 left
💡 Hint
Common Mistakes
Using days not declared in the enum like Friday.
Using lowercase or abbreviated names.
5fill in blank
hard

Fill all three blanks to create a dictionary mapping enum days to their short names.

C Sharp (C#)
var dayShortNames = new Dictionary<Days, string> {
  { Days.[1], "Sun" },
  { Days.[2], "Mon" },
  { Days.[3], "Tue" }
};
Drag options to blanks, or click blank then click option'
ASunday
BMonday
CTuesday
DFriday
Attempts:
3 left
💡 Hint
Common Mistakes
Including days not in the enum like Friday.
Mismatching enum members and short names.