Enum of long values in C#

前端 未结 5 1756
忘掉有多难
忘掉有多难 2021-02-18 13:31

Why does this declaration,

public enum ECountry : long
{
    None,
    Canada,
    UnitedStates
}

require a cast for any of its values?

         


        
5条回答
  •  感动是毒
    2021-02-18 14:24

    AFAIK, you have got to cast.

    The MSDN article says:

    "However, an explicit cast is needed to convert from enum type to an integral type" (either int or long)

    You can check it out:

    Enumeration types (C# reference)

提交回复
热议问题