c# enum string code example
Example 1: string to enum c# 3
StatusEnum MyStatus = (StatusEnum) Enum.Parse(typeof(StatusEnum), "Active", true);
Example 2: c# string enum
public class LogCategory
{
private LogCategory(string value) { Value = value; }
public string Value { get; set; }
public static LogCategory Trace { get { return new LogCategory("Trace"); } }
public static LogCategory Debug { get { return new LogCategory("Debug"); } }
public static LogCategory Info { get { return new LogCategory("Info"); } }
public static LogCategory Warning { get { return new LogCategory("Warning"); } }
public static LogCategory Error { get { return new LogCategory("Error"); } }
}
Example 3: c# enum syntax
enum State
{
Idle,
Walking,
Running,
Jumping,
Climbing,
Attacking
}
Example 4: c# string enum
public static class Status
{
public const string Awesome = "Awesome";
public const string Cool = "Cool";
}