Answers for "c# enum string name"

0

c# get string value of enum

using System;

public class GetNameTest {
    enum Colors { Red, Green, Blue, Yellow };
    enum Styles { Plaid, Striped, Tartan, Corduroy };

    public static void Main() {

        Console.WriteLine("The 4th value of the Colors Enum is {0}", Enum.GetName(typeof(Colors), 3));
        Console.WriteLine("The 4th value of the Styles Enum is {0}", Enum.GetName(typeof(Styles), 3));
    }
}
// The example displays the following output:
//       The 4th value of the Colors Enum is Yellow
//       The 4th value of the Styles Enum is Corduroy
Posted by: Guest on December-15-2020
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
4

c# string enum

public static class Status
{
    public const string Awesome = "Awesome";
    public const string Cool = "Cool";
}
//Not an enum but has a similar effect without needing to convert ints
Posted by: Guest on November-12-2020
0

get key from c# enum for specific value

enum myEnum { firstValue: 1, secondValue 2, thirdValue = 3};
string text = Enum.GetName(typeof(myEnum), 2); // text is "secondValue"
Posted by: Guest on October-27-2020

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language