This is a simple code for converting string representation to Enum
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Blog_CS { public enum State { New, Ready, Stop, Reset }; class Program { private static void Main(string[] args) { const string state = "New"; State currentState = (State)Enum.Parse(typeof(State), state); if (currentState == State.New) { Console.WriteLine("Run state"); } } } }


No comments:
Post a Comment