zoukankan      html  css  js  c++  java
  • 枚举与字符串的互化示例

    using System;

    public class ParseTest
    {
        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));
        }
    }

    /*
    输出结果:

    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

    */

  • 相关阅读:
    0Day – 2011.01.26
    JQuery_PHP 开始新的旅途
    0Day – 2011.01.25
    0Day – 2011.02.04
    Delphi 必须的一致.
    0Day – 2011.01.28
    0Day – 2011.02.23[From B4A]
    足球 看球悲惨的回忆.
    Delphi – EurekaLog6.1.01Ent下载地址
    ubuntu 拨号
  • 原文地址:https://www.cnblogs.com/liancs/p/3879359.html
Copyright © 2011-2022 走看看