How can I get the number of items defined in an enum?
A nifty trick I saw in a C answer to this question, just add a last element to the enum and use it to tell how many elements are in the enum:
enum MyType {
Type1,
Type2,
Type3,
NumberOfTypes
}
In the case where you're defining a start value other than 0, you can use NumberOfTypes - Type1 to ascertain the number of elements.
I'm unsure if this method would be faster than using Enum, and I'm also not sure if it would be considered the proper way to do this, since we have Enum to ascertain this information for us.