Total number of items defined in an enum
Way1
int number=Enum.GetNames(typeof(MYEnum)).Count();
|
Way2
public enum MYEnum{
Dog,
Pig,
Cat,
NumberOfMyEnum
}
static void Main(string[] args)
{
int number=(int)MYEnum.NumberOfMyEnum
}
|
留言
張貼留言