Why does C# 3 allow the implicit conversion of literal zero (0) to any Enum?

前端 未结 5 612
后悔当初
后悔当初 2020-12-06 18:12

C#3 (Visual Studio 2008) introduced a breaking change to the language (http://msdn.microsoft.com/en-us/library/cc713578.aspx, see change 12) that allows any literal zero to

5条回答
  •  生来不讨喜
    2020-12-06 18:40

    It has been allowed since version 1.0. It is the default value of an enum.

    "A literal 0 is implicitly convertible to any enum type. In Visual C# 2005 and earlier versions of the compiler, there are also some constant expressions that evaluate to 0 that can implicitly convert to any enum type, but the rule that determines which of these expressions are convertible is unclear. In Visual C# 2008, all constant expressions that are equal to 0 can be implicitly converted to any enum type."

提交回复
热议问题