C# Enum.ToString() with complete name

后端 未结 6 932
眼角桃花
眼角桃花 2020-12-20 17:26

I am searching a solution to get the complete String of an enum.

Example:

Public Enum Color
{
    Red = 1,
    Blue = 2
}
Color color = Color.Red;

/         


        
6条回答
  •  悲哀的现实
    2020-12-20 17:46

    I have no idea if this is the best way, but it works:

    string colorString = string.Format("{0}.{1}", color.GetType().FullName, color.ToString())
    

提交回复
热议问题