Enum inheriting from int

前端 未结 9 1259
借酒劲吻你
借酒劲吻你 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条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-17 09:26

    Most of the time I don’t care if an enum is signed or unsigned, or how many bits it has, so I just let the system use it’s default that is int.

    However there are times when I do care that the enum is a signed 32 bit int, and then it is good to make it clear that I do care. I would expect a comment as well spelling out why I care.

提交回复
热议问题