例如,我enum在C#中声明了以下内容。
C#代码:
public enum LobMaster :int
{
RetailBroking = 1,
HNI = 2,
TechnologyInfrastructure = 3,
}
Run Code Online (Sandbox Code Playgroud)
cshtml代码:
@int code = 2
@if (LobMaster.RetailBroking == code)
{
}
Run Code Online (Sandbox Code Playgroud)
如果我尝试将int枚举与整数值进行比较,则会显示以下错误消息。
运算符'=='不能应用于类型'LobMaster'和'int'
虽然我的枚举
龙虾大师
已经是int类型。
但是,当我将枚举转换为int并与int值进行比较时,它可以正常工作。所以我的问题是,为什么我需要将enum强制转换为int,因为enum已经是一个int了。