Answers for "enum to string"

C#
1

enum value to string

class Program.
static void Main(string[] args)
{
   Enum wkday = Weekday.Friday;
   Console.WriteLine("Enum string is '{0}'", wkday.ToString());
   Console.ReadKey();
}
Posted by: Guest on February-23-2021
0

Converting Enum to String and Strint to Enum

private enum Status
{
    Awesome = 1,
    Cool = 2
};

public string ConvertEnumToString(Status status)
{
   return status.ToString();
}

public Status ConvertStringToEnum(string status)
{
    return (Status) Enum.Parse(typeof (Status), status);
}

//serializer.Converters.Add(new Newtonsoft.Json.Converters.StringEnumConverter());

//Fast enum
public enum HumanStates
{
	Idle,
    Working,
    Sleeping,
    Eating,
    Dead
     
}

public string FastToString(HumanStates state)
{
	switch(state)
    {
      case HumanStates.Idle:
        	return nameof(HumanStates.Idle);
      case HumanStates.Working:
        	return nameof(HumanStates.Working);
      case HumanStates.Sleeping:
        	return nameof(HumanStates.Sleeping);
      case HumanStates.Eating:
        	return nameof(HumanStates.Eating);
      case HumanStates.Dead:
        	return nameof(HumanStates.Dead);
      default:
        throw new ArgumentOutOfRangeException(nameof(state), state, null);        
    }
}
Posted by: Guest on August-24-2021
0

java enum to string

public enum MyEnum{
	SOMETHING,SOMETHING_ELSE
}
MyEnum enumObject=MyEnum.SOMETHING;
System.out.println(enumObject.toString());
System.out.println(enumObject.name());
Posted by: Guest on April-04-2021
0

chsarp enum to string

class Program  
{  
    static void Main(string[] args)  
    {  
        Enum wkday = Weekday.Friday;  
        Console.WriteLine("Enum string is '{0}'", wkday.ToString());  
        Console.ReadKey();  
    }  
          
    // Enum   
    public enum Weekday  
    {  
        Monday = 0, Tuesday = 1, Wednesday = 2, Thursday = 4, Friday = 5, Saturday = 6, Sunday = 7  
    }  
}
Posted by: Guest on November-16-2020
0

enum to string java

String name = Modes.mode1.name(); // Returns the name of this enum constant, exactly as declared in its enum declaration.
Posted by: Guest on July-15-2021
0

enum to string java

yourEnum.name()
Posted by: Guest on June-01-2021

C# Answers by Framework

Browse Popular Code Answers by Language