You can count the number of constants defined in a C# enumeration with the static Enum.GetNames method. This returns an Array containing the names of the constants defined in the enumeration. You can then check the Array’s Length property.
For example, to get the number of constants defined in the ContentAlignment enumeration:
1 2 3 |
int count = Enum.GetValues( typeof( ContentAlignment ) ).Length; |