C#控制台基础 string,int转为枚举类型
来源:互联网 发布:json base64 编辑:程序博客网 时间:2024/06/06 11:39
镇场诗:慈心积善融学习,技术誓为大家学。善心速造多好事,前人栽树后乘凉。我今于此写经验,愿见文者得启发。
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace ConsoleApplication1{ class Program { public enum fruit:int { apple=0, banana=1 } static void Main(string[] args) { //string转为枚举 fruit food; if (Enum.TryParse<fruit>("apple", out food)) { Console.WriteLine("转换成功 "+food); } else { Console.WriteLine("转换失败"); } //int转为枚举 if (Enum.TryParse<fruit>("1", out food)) { Console.WriteLine("转换成功 "+food); } else { Console.WriteLine("转换失败"); } Console.ReadKey(); } }}
参考链接:http://www.cnblogs.com/pato/archive/2011/08/15/2139705.html
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
感恩帮助过我的人。博客的精髓在技术部分,更在镇场一诗。
我是一个新手,代码还有许多不完善的地方,请您看代码的时候多多思考。
C#是一个优秀的语言,VS是一个优秀的编译软件,二者值得学习。如果您有一些不会的知识,咱们可以相互讨论。
如果您认为代码可以有改进的地方,有错误的地方,请留下评论,我会处理的。
注:如果我的博文无意中侵犯了您的权益,请告知。看到您的告知后,我将及时作出处理。
0 0
- C#控制台基础 string,int转为枚举类型
- C#控制台基础 枚举类型与int,string相互转换
- C# String 类型 转为 Enum 枚举类型
- String 类型 转为 Int 类型
- 将String类型转为int类型
- C#控制台基础 可空类型int?,加法实例
- C#控制台基础 结构体与枚举类型连用示例
- C#控制台 枚举类型声明初始化,输出名称与对应的int值
- C#枚举 枚举和int以及string类型之间的转换 结构 重载 全局变量
- C#基础枚举类型
- c#之枚举类型和int以及string类型的转换
- Java之String类型数据转为int类型
- string类型转为对应的枚举类型,使用Enum.Parse
- c# 学习之8 枚举类型和int string的转换
- C#控制台基础 不用中间变量,交换int,double类型变量
- C#控制台基础 获取一维int类型数组的最大值,最小值
- C#控制台基础 两个int类型数组,求交集,并集,差集
- C#控制台基础 int类型的list中removeall用法示例
- (十三)maven实践-添加依赖
- springmvc使用谷歌captcha生成图片验证码
- SVN无法查看历史,报错Item is not readable
- NetBeans运行error: bin/nativeexecution/Linux-x86_64/pty
- iOS-边框图片,头像边框
- C#控制台基础 string,int转为枚举类型
- Python练习100例-10
- 快速编辑excel 宏快捷键
- ellipsis省略号表示多余内容
- 高级I/O函数之socketpair和dup/dup2
- Error: Found item Attr/font more than one time Error: Execution failed for task
- sdut oj3346 数据结构实验之二叉树七:叶子问题
- Java编程思想第4版-第六章
- python之列表