Answers for "create enum for string type c#$"

C#
4

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"); } }
}
Posted by: Guest on February-19-2021
0

Create Type from String Enum

const GENDERS = ["MALE", "FEMALE", "DIVERSE"] as const;
type Gender = typeof GENDERS[number];
Posted by: Guest on September-15-2021

C# Answers by Framework

Browse Popular Code Answers by Language