| 编程中国 | 业界新闻 | 技术文章 | 视频教程 | 下载频道 | 程序源码 | 个人空间 | 编程论坛
全能ASP/PHP/ASP.NET主机,支持月付专业 MSSQL 数据库空间,支持月付专业 MySQL 数据库空间,支持月付买域名,送MP3、MP4
高端软件开发 = 年薪十万不是梦赛孚耐:软件保护加密专家身份认证令牌USB KEY买空间,免费送域名(厦门中资源)
共有 247 人关注过本帖
标题:枚举问题 请大侠指点
收藏  订阅  推荐  打印 
wangbo1204
Rank: 1
等级:新手上路
帖子:18
积分:316
注册:2007-10-23
枚举问题 请大侠指点

using System;
using System.Collections.Generic;
using System.Text;
namespace 枚举方法
{
   
    public class ParseTest
    {
        [FlagsAttribute]
        enum Colors { Red = 1, Green = 2, Blue = 4, Yellow = 8 };
        public static void Main()
        {
            Console.WriteLine("The entries of the Colors Enum are:");
            foreach (string colorName in Enum.GetNames(typeof(Colors)))
            {
                Console.WriteLine("{0}={1}", colorName,
                                             Convert.ToInt32(Enum.Parse(typeof(Colors), colorName)));
            }
            Console.WriteLine();
            Colors myOrange = (Colors)Enum.Parse(typeof(Colors), "Red, Yellow");
            Console.WriteLine("The myOrange value {1} has the combined entries of {0}",myOrange, Convert.ToInt64(myOrange));
        }
    }
}
这个程序中 Console.WriteLine("The myOrange value {1} has the combined entries of {0}",myOrange, Convert.ToInt64(myOrange));这一句的运行的结果为什么是
The myOrange value 9 has the combined entries of red,Yellow?这个9和Red,Yellow是怎么出来的,“Red,Yellow”中“”有什么特殊作用吗?
搜索更多相关主题的帖子: 枚举  
2007-12-3 23:23
doughty
Rank: 3Rank: 3
等级:中级会员
帖子:344
积分:3838
注册:2007-10-18

我是这样理解的,,...9是:你的YELLOW=8可能往后移了一位..还有你myOrange = (Colors)Enum.Parse(typeof(Colors), "Red, Yellow");
里面的""是字符应该只会显示RED.YELLOW吧,,..
2007-12-4 09:40
关于我们 | 广告合作 | 编程中国 | 清除Cookies | Archiver | WAP | TOP

编程中国 版权所有,并保留所有权利。鲁ICP备08000592号
Powered by Discuz, Processed in 0.051167 second(s), 9 queries.
Copyright©2004-2008, BCCN.NET, All Rights Reserved