Formatting Enumerations


A format specifier can quickly convert an enumerated type into a properly formatted value string:

 enum enumType {     TypeA = 1,     TypeB = 2,     TypeC = 3 } enumType eVal = enumType.TypeB; Console.WriteLine( "{0:g} [" + string.Format( "{0:g}", eVal ) + "]" ); 

Table C-3 shows how to format an enumeration that takes a value of enumType.TypeB.

Table C-3: Formatting an Enumeration Taking a Value of enumType.TypeB

SPECIFIER

TYPE

FORMAT

OUTPUT

G

Default (flag names if available, otherwise decimal)

{0:G}

TypeB

F

Flags always

{0:F}

TypeB

D

Integer always

{0:D}

2

X

Eight-digit hex

{0:X}

00000002




Developing. NET Enterprise Applications
Developing .NET Enterprise Applications
ISBN: 1590590465
EAN: 2147483647
Year: 2005
Pages: 119

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net