How to Count Items in a C# Enum – Programming, Pseudocode Example, C# Programming Example
C# C# Console

How to Count Items in a C# Enum

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:

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: