zoukankan      html  css  js  c++  java
  • Enum枚举

    1.定义

    enum  orientation :byte
        {
             north=1,
             south=2,
             east=3,
             west=4
        }

    2.使用

     //定义enum      

           orientation myOrientation = orientation.east;    

             System.Console.WriteLine(myOrientation);

                //enum->byte        

         byte directionByte = (byte)myOrientation;      

           System.Console.WriteLine(directionByte);

                //byte->enum ; 如果byte值未映射到enum中的一个值,会产生逻辑错误,但不会抛出异常;  

               myOrientation = (orientation)directionByte;         

              System.Console.WriteLine(myOrientation);

                   //enum->toString()        

                     string directionStr = Convert.ToString(myOrientation);

                //String->enum; 如果值不能映射为enum中的一个值,会抛异常;    

                myOrientation = (orientation)Enum.Parse(typeof(orientation), "north");      

             System.Console.WriteLine(myOrientation);

  • 相关阅读:
    十四
    十三
    十二
    十一
    用Linq从一个集合选取几列得到一个新的集合-可改列名
    LINQ入门(完结篇)
    LINQ入门(下篇)
    LINQ入门(中篇)
    LINQ入门(上篇)
    MVC中View往Controllers传数据的方式-已发
  • 原文地址:https://www.cnblogs.com/xiaowei-blog/p/4185032.html
Copyright © 2011-2022 走看看