Extension methods are so cool

Enums in the C-family of languages have always been a little…anemic. Much better than a handful of ints, but anemic. If you want any actual behavior out of them, you either end up with a bag of functions stashed somewhere “convenient”, or rolling your own enum-like behavior in a full-on class.

C# 3.0′s extension methods bring first-class citizenship to enums, albeit in a way that reminds me more of Haskell’s modules than of C# classes. Now we can have member functions for enum values!

(Hey Microsoft, any hope for an EnumOutOfRangeException when someone tries to cast an unsuitable int? Please?)

Tags: , , ,

Comments are closed.