Skip to main content

Posts

Showing posts with the label string formatting for enum

Handling Enumerations in C# as Strings

In Order for an Enumeration in C# to be processed as a string, use the string formats described below, Sample: enum Colors {Red, Green, Blue, Yellow = 12}; Colors myColor = Colors.Yellow; myColor.ToString("g") = Yellow myColor.ToString("G") = Yellow myColor.ToString("x") = 0000000C myColor.ToString("X") = 0000000C myColor.ToString("d") = 12 myColor.ToString("D") = 12 myColor.ToString("f") = Yellow myColor.ToString("F") = Yellow As shown in the above samples, the following format specifiers :   g,G,x,X,d,D,f and F are used to convert a integer based enum value to string format. -- Saravanan