获取的枚举项目总数 [英] Getting total number of enum items
本文介绍了获取的枚举项目总数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有可能获得在运行时由枚举定义的项目总数?
Is it possible to get the total number of items defined by an enum at runtime?
虽然这是pretty高达这一个同样的问题,这个问题涉及到C#,而据我所知道的,所提供的方法不会有在Objective-C的工作。
While it's pretty much the same question as this one, that question relates to C#, and as far as I can tell, the method provided there won't work in Objective-C.
推荐答案
这是枚举
是一个普通的老-C型,因此它不提供动态的运行时信息。
An enum
is a plain-old-C type, therefore it provides no dynamic runtime information.
一替代方法是使用一个枚举的最后一个元素以指示计数:
One alternative is to use the last element of an enum to indicate the count:
typedef enum {
Red,
Green,
Blue,
numColors
} Color;
这篇关于获取的枚举项目总数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文