Enum inheriting from int

前端 未结 9 1278
借酒劲吻你
借酒劲吻你 2020-12-17 08:43

I\'ve found this all over the place in this code:

public enum Blah: int
{
    blah = 0,
    blahblah = 1
}

Why would it need to inherit fro

9条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-17 09:24

    Enums are implicitly backed by integers.
    : int just restates the default, just like void M(); vs. private void M();.

    You can also create enums that are backed by other intergral types, such as enum GiantEnum : long.

提交回复
热议问题