zoukankan      html  css  js  c++  java
  • 关于enum的一些常用方法

    今天在开发的过程中,需要用到Enum,就顺便查些资料,做下简单记录.

    定义一个enum

    enum Colors{ Red, Green, Blue, Yellow};

    enum Colors{ Red=1, Green=2, Blue=3, Yellow=4};

    1.得到枚举中常数值的数组。

    for each(int i in Enum.GetValues(typeof(Colors)))
    Console.WriteLine(i);

    2. 检索指定枚举中常数名称的数组

    for each(string s in Enum.GetNames(typeof(Colors)))
    Console.WriteLine(s);

    3.转换Integer常数值和转换一个String常数名到Eumn实例

     

    public Colors GetCoorsInstance(string value){

        Colors returnValue = (Colors)Enum.Parse(typeof(Colors), value);
        return returnValue;

    }

  • 相关阅读:
    构建之法阅读笔记05
    四元数(Quaternion)
    httpclient
    两种unity双击事件
    WWW网络请求
    Unity混合天空盒
    unity message
    unity射线检测
    unity 初始化数据存储问题
    Awake,start,update,OnEnable,OnDisable
  • 原文地址:https://www.cnblogs.com/ghfsusan/p/1414226.html
Copyright © 2011-2022 走看看