C# 枚举 字符串 转换

普通方法
这种方法尽管很SB但确实可以解决问题
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
string SelPath = "";
switch (comboBox1.SelectedIndex)
{
case : SelPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData); break;
case : SelPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.CommonApplicationData); break;
case : SelPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.LocalApplicationData); break;
case : SelPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Cookies); break;
case : SelPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop); break;
case : SelPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Favorites); break;
case : SelPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.History); break;
case : SelPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.InternetCache); break;
case : SelPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Programs); break;
case : SelPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyComputer); break;
case : SelPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyMusic); break;
case : SelPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyPictures); break;
case : SelPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Recent); break;
case : SelPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.SendTo); break;
case : SelPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.StartMenu); break;
case : SelPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Startup); break;
case : SelPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.System); break;
case : SelPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Templates); break;
case : SelPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.DesktopDirectory); break;
case : SelPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal); break;
case : SelPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments); break;
case : SelPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.ProgramFiles); break;
case : SelPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.CommonProgramFiles); break;
}
Text = SelPath;
}
使用 Enum.Parse 方法 (Type, String)
[ComVisibleAttribute(true)]
public static Object Parse(
Type enumType,
string value
)
正解方法
本来一句就可以解决的 所以坚决用一句代码解决
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
string SelPath = System.Environment.GetFolderPath(
(System.Environment.SpecialFolder)Enum.Parse(typeof(System.Environment.SpecialFolder), comboBox1.Text)
);
Text = SelPath;
}
原本地址 http://www.cnblogs.com/pato/archive/2011/08/15/2139705.html
C# 枚举 字符串 转换的更多相关文章
- QMetaEnum利用Qt元数据实现枚举(enum)类型值及字符串转换
版权声明:若无来源注明,Techie亮博客文章均为原创. 转载请以链接形式标明本文标题和地址: 本文标题:QMetaEnum利用Qt元数据实现枚举(enum)类型值及字符串转换 本文地址:ht ...
- C# 字符串string类型转换成DateTime类型 或者 string转换成DateTime?(字符串转换成可空日期类型)
在c#中,string类型转换成DateTime类型是经常用到的,作为基本的知识,这里在此做个小结.一般来说可以使用多种方法进行转换,最常用的就是使用Convert.ToDateTime(string ...
- Gson将字符串转换成JsonObject和JsonArray
以下均利用Gson来处理: 1.将bean转换成Json字符串: public static String beanToJSONString(Object bean) { return new Gso ...
- JS 实现"可读"字符串转换成"二进制的01"字符串
问题起源 看过一个漫画, 两位程序员在办公司交流, 可是说的语言却是010101类似的字符串.周围人很是惊异.计算机的世界,确实是由01组成的.今天突然想实现这个编码转换. 解决思路 学过C语言的都知 ...
- C标准库-数值字符串转换与内存分配函数
原文链接:http://www.orlion.ga/977/ 一.数值字符串转换函数 #include <stdlib.h> int atoi(const char *nptr); dou ...
- js 字符串转换数字
方法主要有三种转换函数.强制类型转换.利用js变量弱类型转换. 1. 转换函数: js提供了parseInt()和parseFloat()两个转换函数.前者把值转换成整数,后者把值转换成浮点数.只有对 ...
- List转换成json格式字符串,json格式字符串转换成list
一.List转换成json字符串 这个比较简单,导入gson-x.x.jar, List<User> users = new ArrayList<User>(); Gson g ...
- PHP面试题之驼峰字符串转换成下划线样式例子
自己在看到这个问题的时候,想到的是用ASCII码来处理,没往万能的正则上去想.好吧,下面来看看答案: 答案1: 代码如下 复制代码 $str = 'OpenAPI'; $length = mb_str ...
- js 字符串转换成数字的三种方法
在js读取文本框或者其它表单数据的时候获得的值是字符串类型的,例如两个文本框a和b,如果获得a的value值为11,b的value值为9 ,那么a.value要小于b.value,因为他们都是字符串形 ...
随机推荐
- after I see Little Dorrit
也许是我太追名逐利,所以我不肯承认自己花费了大把的时间看电影,通过写博客好像自己从中感悟到了什么,好像看电影也是一种学习的方式. 也许是我平静自内心的方式,我太忙于玩或者学习,甚至没有机会非常沉静 一 ...
- IEnumerable,ICollection,IList,List区别
做C#的同学们,都知道,一类只能有一个继承类,但可以实现多个接口.这句话就告诉我们:IEnumerable,ICollection,IList,List区别了 首先我看看 IEnumerable: / ...
- PADS故障解决
1. 点击PADS后就会出现以下: "The directory pointed by the FileDir INI file entry cannot be found.Aborting ...
- [转]如何根据cpu的processor数来确定程序的并发线程数量
原文:http://blog.csdn.net/kirayuan/article/details/6321967 我们可以在cat 里面发现processor数量,这里的processor可以理解为逻 ...
- The Bellman-Ford algorithm
This algorithm deals with the general case, where G is a directed, weight graph, and it can contains ...
- GRUB引导——menu.lst的写法
转自menu.lst的写法.menu.lst的写法 1.menu.lst的写法之一 首先我们看一下我的Fedora 4.0 中的/boot/grub/menu.lst 的内容: default=0 ...
- PHP 切割字符串 点号 不用双斜杠
$name = "tupian.png"; $nameArr = explode(".", $name); 习惯了Java的程序员容易写成 $nameArr = ...
- 【网络流24题】No. 17 运输问题 (费用流)
[题意] W 公司有 m 个仓库和 n 个零售商店.第 i 个仓库有ai 个单位的货物:第 j 个零售商店需要b j 个单位的货物. 货物供需平衡,即SIGMA(A)=SIGMA(B). 从第 i 个 ...
- gdb调试高级用法
Linux下进程崩溃时定位源代码位置 如何在调试内核时,同时可以调试应用程序的做法: (cskygdb) c Continuing. ^C Program received signal SIGINT ...
- [转贴]从零开始学C++之异常(一):C语言错误处理方法、C++异常处理方法(throw, try, catch)简介
一.C语言错误处理方法 1.返回值(if … else语句判断错误) 2.errno(linux 系统调用) 3.goto语句(函数内局部跳转) 4.setjmp.longjmp(Do not use ...