惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

I
InfoQ
S
SegmentFault 最新的问题
T
Tailwind CSS Blog
美团技术团队
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
爱范儿
爱范儿
宝玉的分享
宝玉的分享
Last Week in AI
Last Week in AI
量子位
博客园 - Franky
酷 壳 – CoolShell
酷 壳 – CoolShell
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
J
Java Code Geeks
The Cloudflare Blog
小众软件
小众软件
云风的 BLOG
云风的 BLOG
WordPress大学
WordPress大学
P
Proofpoint News Feed
Stack Overflow Blog
Stack Overflow Blog
aimingoo的专栏
aimingoo的专栏
Y
Y Combinator Blog
B
Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
C
Check Point Blog

博客园 - 费哥

VC++实现应用程序对插件的支持(转) typedef的四个用途和两个陷阱(转) c#动态创建ODBC数据源 设为首页,加入收藏,联系我们 - 费哥 - 博客园 ASP.NET 2.0中CSS失效 ADO.NET更新ACCESS碰到的怪异问题 DataGrid中的數據輸出到Excel 对 Windows 窗体控件进行线程安全调用 将参数传递给线程(Vc#2005) 创建合理位置的线标注 Sql2005导出SQL2000格式的脚本 将外部图块插入当前图形(c#代码) 无法将顶级控件添加到控件 使用Microsoft Visual Studio2005开发ObjectARX设置 CS1595:已在多处定义 软件设计师考试大纲 <<设计模式可复用面向对象软件的基础>>--组合模式(Composite) <<设计模式可复用面向对象软件的基础>>--设计模式怎样解决设计问题 <<设计模式可复用面向对象软件的基础>>读书笔记--(第一章)引言
c#枚举的用法及遍历方法
费哥 · 2008-03-26 · via 博客园 - 费哥

来自MSDN
枚举可用来存储字符串与数字的值对,相当于一个对照表
常用方法:GetName(),GetValue(),Parse()

 1 using System;
 2 
 3 public class EnumTest {
 4     enum Days { Saturday, Sunday, Monday, Tuesday, Wednesday, Thursday, Friday };
 5     enum BoilingPoints { Celcius = 100, Fahrenheit = 212 };
 6     [FlagsAttribute]
 7     enum Colors { Red = 1, Green = 2, Blue = 4, Yellow = 8 };
 8 
 9     public static void Main() {
10 
11         Type weekdays = typeof(Days);
12         Type boiling = typeof(BoilingPoints);
13 
14         Console.WriteLine("The days of the week, and their corresponding values in the Days Enum are:");
15 
16         foreach ( string s in Enum.GetNames(weekdays) )
17             Console.WriteLine( "{0,-11}= {1}", s, Enum.Format( weekdays, Enum.Parse(weekdays, s), "d"));
18 
19         Console.WriteLine();
20         Console.WriteLine("Enums can also be created which have values that represent some meaningful amount.");
21         Console.WriteLine("The BoilingPoints Enum defines the following items, and corresponding values:");
22 
23         foreach ( string s in Enum.GetNames(boiling) )
24             Console.WriteLine( "{0,-11}= {1}", s, Enum.Format(boiling, Enum.Parse(boiling, s), "d"));
25 
26         Colors myColors = Colors.Red | Colors.Blue | Colors.Yellow;
27         Console.WriteLine();
28         Console.WriteLine("myColors holds a combination of colors. Namely: {0}", myColors);
29     }
30 }
31 
32