我有一个enum
课程。我正在使用 C#。我需要将其从enum
转换为string
。例如,Language.En将返回string
。
public enum Language
{
EN,
SV,
DE
}
答案 0 :(得分:8)
只需在枚举上调用ToString()。
Language.EN.ToString();
答案 1 :(得分: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