什么是枚举数据类型..为什么我们需要使用枚举 [英] what is enum data type.. why we have need to use enum
本文介绍了什么是枚举数据类型..为什么我们需要使用枚举的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
什么是枚举数据类型..为什么我们需要使用枚举,请解释.. Thnx提前
解决方案
enum关键字用于声明枚举,一种由称为枚举器列表的一组命名常量组成的独特类型。
public class EnumTest
{
enum 天数{太阳,周一,周二,周三,周四,周五,周六};
静态 void Main()
{
int x =( int )Days.Sun;
int y =( int )Days.Fri;
Console.WriteLine( Sun = {0},x);
Console.WriteLine( Fri = {0},y);
}
}
在上面的示例中,枚举可以直接表示和使用天数。
因此,没有必要在集合中定义天数。
来源 - 枚举(C#参考) [ ^ ]。
枚举C#
< br>
参考: enums-in-C-Sharp [ ^ ]
what is enum data type.. why we have need to use enum , please explain .. Thnx in advance
解决方案
The enum keyword is used to declare an enumeration, a distinct type that consists of a set of named constants called the enumerator list.
public class EnumTest { enum Days { Sun, Mon, Tue, Wed, Thu, Fri, Sat }; static void Main() { int x = (int)Days.Sun; int y = (int)Days.Fri; Console.WriteLine("Sun = {0}", x); Console.WriteLine("Fri = {0}", y); } }
In the above example, enums can represent and use days directly.
As a result, there is no need to define days in a collection.
Source - enum (C# Reference)[^].
Enum in C#
Refer: enums-in-C-Sharp[^]
这篇关于什么是枚举数据类型..为什么我们需要使用枚举的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文