1

I have an enum class. I am using C#. I need to convert it from enum to string. For example, Language.En will return as string.

public enum Language
{
    EN,
    SV,
    DE
}
0

2 Answers 2

9

Just call ToString() on the Enum.

Language.EN.ToString();
Sign up to request clarification or add additional context in comments.

1 Comment

@Ian specifying Culture/FormatProvider in Enum.ToString is deprecated/obsolete -> msdn.microsoft.com/en-us/library/System.Enum.ToString.aspx
1
//try this :)

using System;

enum Priority
{
    never,
    killed,
    beauty
}

class Program
{
    static void Main()
    {
    // Write string representation for killed.
    Priority enum1 = Priority.killed;
    string value1 = enum1.ToString();

    // Loop through enumerations and write string representations
    for (Priority enum2 = Priority.never; enum2 <= Priority.beauty; enum2++)
    {
        string value2 = enum2.ToString();
        Console.WriteLine(value2);
    }
    }
}

Output
never
killed
beauty

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.