In addition to other types, you can extend the functionality of an enumerated type using extension methods.
Below is an extension method that extends the DayOfWeek enumerated type.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | public static string Activity(this DayOfWeek day) { string activity = ""; switch (day) { case DayOfWeek.Sunday: activity = "Reading paper"; break; case DayOfWeek.Monday: activity = "Grumbling"; break; case DayOfWeek.Tuesday: activity = "Eating tacos"; break; case DayOfWeek.Wednesday: activity = "Reading"; break; case DayOfWeek.Thursday: activity = "Cursing"; break; case DayOfWeek.Friday: activity = "Celebrating"; break; case DayOfWeek.Saturday: activity = "Hiking"; break; } return activity; }} |
We can now call the Activity method on any variable or constant whose type is DayOfWeek.
1 2 3 4 | DayOfWeek today = DayOfWeek.Thursday;Console.WriteLine(today.Activity());Console.WriteLine(DayOfWeek.Friday.Activity()); |

