Enum 0 value inconsistency

前端 未结 1 1283
情书的邮戳
情书的邮戳 2021-01-17 16:32

Example code :

    public enum Foods
    {
        Burger,
        Pizza,
        Cake
    }

    private void button1_Click(object sender, EventArgs e)
            


        
1条回答
  •  悲&欢浪女
    2021-01-17 17:19

    Yes, the literal 0 is implicitly convertible to any enum type and represents the default value for that type. According to the C# language specification, in particular section 1.10 on enums:

    The default value of any enum type is the integral value zero converted to the enum type. In cases where variables are automatically initialized to a default value, this is the value given to variables of enum types. In order for the default value of an enum type to be easily available, the literal 0 implicitly converts to any enum type. For the default value of an enum type to be easily available, the literal 0 implicitly converts to any enum type.

    0 讨论(0)
提交回复
热议问题