在一个枚举定义的项目总数总数、定义、项目

由网友(我們一起走過1314)分享简介:我怎样才能在一个枚举定义的项目的数量?How can I get the number of items defined in an enum?推荐答案您可以使用静态方法 Enum.GetNames 返回重新$ P $数组psenting的名字在枚举的所有项目。该数组的长度属性等于在枚举定义的项目数You ca...

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

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;
阅读全文

相关推荐

最新文章