如何从声明的枚举中分配新变量
public enum FontStyle
{
Regular = 0;
Bold =1;
Italic = 2
}
// dont know what Type to cast it :/
TYPE fontstyle = FontStyle.Bold;
Run Code Online (Sandbox Code Playgroud)
我不确定要使用哪个TYPE,它包含在System.Drawing类中.
枚举是类型,因此您的变量应该是以下类型FontStyle:
FontStyle fontstyle = FontStyle.Bold;
Run Code Online (Sandbox Code Playgroud)
这是类型,FontStyle即枚举是一流的类型.
public enum FontStyle
{
Regular = 0;
Bold =1;
Italic = 2
}
// No need to cast it
FontStyle fontstyle = FontStyle.Bold;
Run Code Online (Sandbox Code Playgroud)
编辑:也许你有这样的代码:
if(1 == 1)
FontStyle fontstyle = FontStyle.Bold;
Run Code Online (Sandbox Code Playgroud)
对于您的错误(嵌入式语句不能是声明或带标签的语句),请在块语句中包含您的代码,例如
if(1 == 1)
{
FontStyle fontstyle = FontStyle.Bold;
}
Run Code Online (Sandbox Code Playgroud)