在一个枚举定义的项目总数 [英] Total number of items defined in an enum

查看:331
本文介绍了在一个枚举定义的项目总数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能在一个枚举定义的项目的数量?

How can I get the number of items defined in an enum?

推荐答案

您可以使用静态方法 Enum.GetNames 返回重新$ P $数组psenting的名字在枚举的所有项目。该数组的长度属性等于在枚举定义的项目数

You can use the static method Enum.GetNames which returns an array representing the names of all the items in the enum. The length property of this array equals the number of items defined in the enum

var myEnumMemberCount = Enum.GetNames(typeof(MyEnum)).Length;

这篇关于在一个枚举定义的项目总数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆