通过字符串找到具体枚举(涉及到反射)

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 
 7 namespace ConsoleApp1
 8 {   public enum QQstate
 9     {
10         online,
11         offline,
12         leave,
13         busy,
14         Qme
15     }
16 
17     class Program
18     {
19         static void Main(string[] args)
20         {
21             String s = "1";
22 
23             //通过字符串找到具体枚举(涉及到反射)
24             QQstate state = (QQstate)Enum.Parse(typeof(QQstate), s);
25             Console.WriteLine(state);
26             Console.ReadKey();
27 
28 
29         }
30     }
31 }

 

posted on 2018-04-07 15:38  三盛乙烯  阅读(190)  评论(0编辑  收藏  举报

导航