The underlying type of your enum is still int, just that there's an implicit conversion from char
to int
for some reason. Your enum is equivalent to
TransactionTypeCode { Shipment = 83, Receipt = 82, }
Also note that enum
can have any integral type as underlying type except char
, probably for some semantic reason. This is not possible:
TransactionTypeCode : char { Shipment = 'S', Receipt = 'R', }
To get the char
value back, you can just use a cast.
var value = (char)TransactionTypeCode.Shipment;
// or to make it more explicit:
var value = Convert.ToChar(TransactionTypeCode.Shipment);
The second one causes boxing, and hence should preform worse. So may be slightly better is
var value = Convert.ToChar((int)TransactionTypeCode.Shipment);
but ugly. Given performance/readability trade-off I prefer the first (cast) version..