Tuesday 3 August 2004

c# Enums

Enums are a very useful way to improve code readability, speed-up coding (think intellisense autocomplete) and enforce business rules... but there are also niggly little issues like having to figure out the Enum.Parse method and how to AND/OR Enums together using the [Flags] attribute.

Thankfully, here's a very useful post of links to all sorts of Enum-related info
Enums + Attributes = Swiss Army Knife

And a very useful sample lives here Associating string values to items in code with code.

Decorating Enums with string attributes sounds like it could be used to solve two ongoing problems:
  • localizing(translating) the meaning of an Enum for display to a user, maybe using some sort of 'translation key' attribute; and
  • linking the Enum type to some underlying database lookup table to which it is related...

No comments:

Post a Comment

Note: only a member of this blog may post a comment.