What's the use-case for specifying the underlying type in enums?

后端 未结 3 1069
名媛妹妹
名媛妹妹 2021-01-04 01:35

What is the point of having

enum SomeEnum : byte // <----
{
  SomeValue = 0x01,
  ...
}

when you have to make a cast just to assign it t

3条回答
  •  被撕碎了的回忆
    2021-01-04 01:47

    From enum (C# Reference)

    The underlying type specifies how much storage is allocated for each enumerator. However, an explicit cast is needed to convert from enum type to an integral type.

提交回复
热议问题