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

推荐订阅源

Stack Overflow Blog
Stack Overflow Blog
Vercel News
Vercel News
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
J
Java Code Geeks
M
MIT News - Artificial intelligence
Microsoft Azure Blog
Microsoft Azure Blog
B
Blog RSS Feed
MongoDB | Blog
MongoDB | Blog
G
Google Developers Blog
Engineering at Meta
Engineering at Meta
量子位
S
SegmentFault 最新的问题
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
A
About on SuperTechFans
P
Proofpoint News Feed
Last Week in AI
Last Week in AI
Recent Announcements
Recent Announcements
腾讯CDC
I
InfoQ
F
Fortinet All Blogs
Hugging Face - Blog
Hugging Face - Blog
Blog — PlanetScale
Blog — PlanetScale
H
Help Net Security
爱范儿
爱范儿

博客园 - changchang

SQL中的join用法(zt) 远程桌面 Web 连接 RTM、RC、CTP版本的含义(ZT) Culture Name(转) - changchang - 博客园 MPEG、RM、WMV电影文件格式转换指南(转) PDF文件相关下载 Form验证(转) .net操作文件的基本方法总结 - changchang - 博客园 JavaScript动态的为元素添加事件 dotnet下Request对象获取客户端数据的方式比较(Request.Params) - changchang - 博客园 (转载)一个大家不常用到,却很有用的页面间传值方法(Context.Handler) - changchang - 博客园 CuteEditor学习总结技巧 Javascript图片幻灯片的实现 Window下配置SVN服务器与客户端 Javascript访问html页面的控件 深入理解.net的事件与委托机制 asp.net控件本质 google map简单实现 asp.net 2.0发送和接收邮件总结
.net下枚举的用法 - changchang - 博客园
changchang · 2007-12-22 · via 博客园 - changchang

     在一次项目中需要把枚举的值添加到Combox中去,需要对枚举进行操作。经过学习总结如下,也便于以后查询:
public enum Colors { Red = 1, Green = 2, Blue = 4, Yellow = 8 };
1.根据name获得Enum的类型:
Colors mycolor = (Colors)Enum.Parse(typeof(Colors),"red",true);
(int)mycolor1=1
2.根据value获得Enum的类型:
Colors mycolor = (Colors)Enum.Parse(typeof(Colors),"1",true);
mycolor2.ToString()=Red
3.遍历枚举内容
foreach(string s in Enum.GetNames(typeof(Colors)))
{
    //to do
}
4.怎样确定一个名称或值是枚举中的一个
Enum.IsDefined(typeof(myenum),object(name or value))
5.怎样确定一个类型:  Type t = mycolor.GetType();
                   Type t1 =typeof(Colors);
                   Type t2 = Type.GetType("namespace.Colors");
补充:
Colors myOrange = (Colors)Enum.Parse(typeof(Colors), "Red, Blue,Yellow");
The myOrange value has the combined entries of [myOrange.ToString()]=13

Colors myOrange2 = (Colors)Enum.Parse(typeof(Colors), "Red, Blue");
The myOrange2 value has the combined entries of [myOrange2.ToString()]=5

另:
x.gettype和typeof的用法
1.判断某个实例是否某个类型
  c#  o is classname
  vb   typeof o is classname//必须是引用类型。typeof且必须和is联用
2.c# typeof(int)
   bv gettype(integer)
3.object类的方法
   c# o.GetType
   vb  o.GetType

付出最大努力,追求最高成就。