C#枚举类型使用的一点总结

开发 后端
C#枚举类型使用的一点总结主要是向你讲解C#枚举类型使用过程中的一点体会和知识点的强调,希望对你学习C#枚举类型有所帮助。

C#枚举类型使用的时候需要掌握的有哪些方面呢?首先我们来看看一个例子:

  1. public enum Colors { Red = 1, Green = 2, 
  2. Blue = 4, Yellow = 8 };   
  3.  
  4. The entries of the Colors Enum are:  
  5. Red  
  6. Green  
  7. Blue  
  8. Yellow 

C#枚举类型使用的一点总结之根据name获得Enum的类型:

  1. Colors mycolor = (Colors)Enum.Parse(  
  2. typeof(Colors),"red",true);  
  3. (int)mycolor1=1  
  4. mycolor1.GetTypeCode=Int32 

C#枚举类型使用的一点总结之根据value获得Enum的类型:

  1. Colors mycolor = (Colors)Enum.Parse(  
  2. typeof(Colors),"1",true);  
  3. mycolor2.ToString()=Red  
  4. mycolor2.GetTypeCode=Int32 

C#枚举类型使用的一点总结之遍历枚举内容

  1. foreach(string s in Enum.GetNames(typeof(Colors)))  
  2. {  
  3. //to do   
  4. }  
  5.  
  6.  
  7. Colors myOrange = (Colors)Enum.Parse(  
  8. typeof(Colors), "Red, Blue,Yellow");  
  9. The myOrange value has the combined   
  10. entries of [myOrange.ToString()]=13  
  11.  
  12.  
  13. Colors myOrange2 = (Colors)Enum.Parse(  
  14. typeof(Colors), "Red, Blue");  
  15. The myOrange2 value has the combined   
  16. entries of [myOrange2.ToString()]=5  

C#枚举类型使用的一点总结的内容就向你介绍到这里,希望对你了解和学习C#枚举类型有所帮助。

【编辑推荐】

  1. C#枚举类型实例解析
  2. C#枚举类型开发学习心得
  3. C#枚举类型学习之基础讲解
  4. C#枚举类型语法浅析
  5. C#枚举类型基础学习浅析
责任编辑:仲衡 来源: tz8.net
相关推荐

2009-08-17 18:15:23

C# 枚举使用

2009-08-28 16:30:24

C#线程

2009-08-18 09:37:14

C#枚举类型

2009-08-18 17:20:17

C#操作符重载

2009-08-19 11:23:12

C#操作Word

2009-08-27 17:50:09

interface接口

2009-08-13 17:52:13

C#构造函数

2009-09-09 10:53:25

C# MessageB

2009-08-18 10:17:25

C#枚举类型

2009-08-18 10:47:40

C#枚举类型

2012-03-27 08:49:19

Json

2009-08-18 12:52:33

C#枚举类型

2009-08-18 10:35:46

C#枚举类型

2009-08-14 11:29:28

C#创建Windows

2009-08-18 13:00:59

C#枚举类型

2009-08-18 17:34:25

C#操作符重载应用

2009-08-19 13:49:14

C#操作注册表

2009-09-03 14:28:23

C#日期格式化

2009-09-14 20:17:05

并行LINQ

2009-08-18 10:30:30

C#枚举
点赞
收藏

51CTO技术栈公众号