Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I change the type of an enum?

Tags:

c#

enums

By default, C# enums are stored as integers. I'd like to make it a short instead. Is there a way to do this?

like image 599
Daniel T. Avatar asked Oct 23 '25 16:10

Daniel T.


2 Answers

sure, this can be done, but it has to be an integral type ( byte, short, int, etc.) except char...

enum myEnum : short
{
    FirstValue = 0,
};

here is the MSDN docs

like image 69
Muad'Dib Avatar answered Oct 25 '25 05:10

Muad'Dib


Like this:

enum MyEnum : short
{
  ...
}
like image 38
RPM1984 Avatar answered Oct 25 '25 05:10

RPM1984



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!