Total number of items defined in an enum in C#
You can use the static methodEnum.GetNames
or Enum.GetValues
which returns an array representing the names or values of all the items in the enum. The length property of this array equals the number of items defined in the enum.See below example
int count = Enum.GetValues(typeof(EnumType)).Length;
int count = Enum.GetNames(typeof(EnumType)).Length;