Monday, July 18, 2005

Enumerations

When I first learned programming it was difficult for me to perceive the importance of enumerations (i.e. enum in C++). Then I moved from C++ to Java and I missed them. Now, with C#, enumerations are back... and the sweet thing about them is you can print them or add them to a string and their declaration name prints out instead of their value.

For instance,

enum Choice
{
Yes = 1,
No = 2
}


String strChoice = "Does Ian Smith actually like Debbie Gibson? " + Choice.Yes;

actually prints out, "Does Ian Smith actually like Debbig Gibson? Yes"

cool, no?

(PS, you c++ types should note that you don't have to follow the closed bracket with a semi-colon -- ahhh, feel the Java influence)

No comments: