web analytics

How to Get the Items Count of an Enum type in the .NET?

Options

codeling 1599 - 6654
@2016-01-21 10:34:14

As you know, the Enum.GetValues() method can be used to retrieve an array of the values of the constants in a specified enumeration. Based on the that, it is easy to figure out the the value count of an Enum type, see the following code:

enum Styles { Plaid = 0, Striped = 23, Tartan = 65, Corduroy = 78 };

int count = Enum.GetValues(typeof(Styles)).Length

The result will be 4.

Comments

You must Sign In to comment on this topic.


© 2024 Digcode.com