How to change the type of enumeration?

By default, C # enums are stored as integers. I would like to make it shorter. Is there any way to do this?

+3
source share
4 answers

Of course, this can be done, but it must be an integral type (byte, short, int, etc.), except for char ...

enum myEnum : short
{
    FirstValue = 0,
};

here are the MSDN docs

+8
source

Like this:

enum MyEnum : short
{
  ...
}
+2
source

,

enum Range : short {Max = 6, Min = 1, Mid = 3};
0

Source: https://habr.com/ru/post/1763012/


All Articles