标题:枚举问题 请大侠指点
只看楼主
wangbo1204
Rank: 1
等 级:新手上路
帖 子:18
专家分:0
注 册:2007-10-23
 问题点数:0 回复次数:1 
枚举问题 请大侠指点
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-03 23:23
doughty
Rank: 1
等 级:新手上路
帖 子:372
专家分:0
注 册:2007-10-18
得分:0 
我是这样理解的,,...9是:你的YELLOW=8可能往后移了一位..还有你myOrange = (Colors)Enum.Parse(typeof(Colors), "Red, Yellow");
里面的""是字符应该只会显示RED.YELLOW吧,,..
2007-12-04 09:40



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-190194-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.554851 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved