Convert enum value to string representation according to the specified format in CSharp
Description
The following code shows how to convert enum value to string representation according to the specified format.
Example
//from w w w . jav a 2s . c o m
using System;
enum Colors { Red, Green, Blue, Yellow };
public class FormatTest {
public static void Main() {
Colors myColor = Colors.Blue;
Console.WriteLine(Enum.Format(typeof(Colors), myColor, "d"));
Console.WriteLine(Enum.Format(typeof(Colors), myColor, "x"));
}
}
The code above generates the following result.