枚举的主要用途是什么? [英] What is main use of Enumeration?
问题描述
在c#中使用枚举是什么?
What is main use of Enumeration in c#?
已编辑: -
假设我想将字符串变量与任何枚举项目,然后如何在c#中执行此操作?
Edited:- suppose I want to compare the string variable with the any enumeration item then how i can do this in c# ?
推荐答案
通常,您会发现有些东西 - 数据,分类,任何 - 最好表示为可以用整数表示的几个离散状态之一。典型的例子是一年的几个月。我们希望一年中的几个月可以表现为两个字符串(2010年8月19日)和数字(8/19/2010)。 枚举
提供了一个简洁的方式来为一组整数分配名称,所以我们可以使用简单的循环遍历整数来移动几个月。
Often you find you have something - data, a classification, whatever - which is best expressed as one of several discrete states which can be represented with integers. The classic example is months of the year. We would like the months of the year to be representable as both strings ("August 19, 2010") and as numbers ("8/19/2010"). Enum
provides a concise way to assign names to a bunch of integers, so we can use simple loops through integers to move through months.
这篇关于枚举的主要用途是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!