zoukankan      html  css  js  c++  java
  • Enum.Parse

    using System;

    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.ReadLine();
        }
    }

    运行结果:

    /*
    This code example produces the following results:

    The entries of the Colors Enum are:
    Red=1
    Green=2
    Blue=4
    Yellow=8

    The myOrange value 9 has the combined entries of Red, Yellow

    */ 


  • 相关阅读:
    正则表达式
    数组去重
    [WOJ4354] 蜀石经
    [NOI2002] 银河英雄传说
    [洛谷P2186] 小Z的栈函数
    [洛谷P2756]飞行员配对方案问题
    [洛谷P2071] 座位安排
    [洛谷P2417]课程
    [洛谷P1640] [SCOI2010]连续攻击游戏
    [洛谷P3512 [POI2010]PIL-Pilots]
  • 原文地址:https://www.cnblogs.com/zhangpengshou/p/2388366.html
Copyright © 2011-2022 走看看