This article uses a simple example to illustrate the method of obtaining the number of elements in an enumeration. It is a skill that needs to be firmly mastered for C# learning. Share it for your reference. The details are as follows:
To implement this function, you can use the GetNames(Type t) method of the enumeration base class to get a list of elements in an enumeration.
The specific function codes are as follows:
enum EnumTest { type1, type2, } class Program { static void Main(string[] args) { EnumTest e = new EnumTest(); string[] values = (()); } }
I hope that the examples described in this article will be helpful to everyone to learn C# programming.