博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
enum和int、string的转换操作
阅读量:6709 次
发布时间:2019-06-25

本文共 681 字,大约阅读时间需要 2 分钟。

enum Countries
{
    中国 = 5,
    美国,
    俄罗斯,
    英国,
    法国
}
    • 和 int
      • enum -> int
        int num = (int)Countries.中国; //num=5
        int[] nums = (int[])Enum.GetValues(typeof(Countries));
        //nums={5,6,7,8,9}
      • int -> enum
        Countries country = (Countries)8;
        //country=Countries.英国
      • //http://hovertree.com/menu/csharp/
    • enum 和 string
      • enum -> string
        string str1 = Countries.俄罗斯.ToString(); //str1="俄罗斯";
        string str2 = Enum.GetName(typeof(Countries), 7);
        //str2="俄罗斯";
        string[] strArray = Enum.GetNames(typeof(Countries));
        //strArray={"中国","美国","俄罗斯","英国","法国"};
      • string-> enum
        Countries myCountry = (Countries)Enum.Parse(typeof(Countries), "中国");
        //myCountry=Countries.中国
推荐:

转载于:https://www.cnblogs.com/roucheng/p/csenum.html

你可能感兴趣的文章
canvas元素简易教程(10)(转自火狐,自己只写了简单的代码分析)
查看>>
Scala下划线_使用
查看>>
2018-2019-1 20165324 《信息安全系统设计基础》第三周 缓冲区溢出漏洞实验
查看>>
centos 7.3二进制安装mariadb10.2.8完美步骤
查看>>
Mysql实现企业级日志管理、备份与恢复实战
查看>>
linux网卡eth1如何修改为eth0
查看>>
poj 3525 凸多边形多大内切圆
查看>>
Android UI:ListView -- SimpleAdapter
查看>>
理解nginx的配置
查看>>
UserWarning: Method on_batch_end() is slow compared to the batch update. Check your callbacks.
查看>>
.net序列化与反序列化
查看>>
【Android-3】Android中的任务栈(Task)
查看>>
maven
查看>>
Java反射
查看>>
旅行线路
查看>>
内存溢出和内存泄漏的区别、产生原因以及解决方案
查看>>
ns3重要类
查看>>
springboot2.1.5集成单节点elasticsearch6.4.0
查看>>
noi1696 逆波兰表达式
查看>>
RDD编程 上(Spark自学三)
查看>>