通过字符串找到具体枚举(涉及到反射)
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 }