各位兄弟姐妹们,C#.net enum 怎样转换成 string Enum.GetNames Enum.GetValues 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 enum Gun{ ShortGun, MachineGun, Rifle = 4}string str;str = Gun.Rifle.ToString(); // Riflestr = Gun.Rifle.ToString("D"); // 10 correction:enum Gun { ShortGun, MachineGun, Rifle = 10 } string str; str = Gun.Rifle.ToString(); // Rifle str = Gun.Rifle.ToString("D"); // 10 str = Gun.Rifle.ToString("X"); // 0000000A enum 是枚举 你要转什么 没讲清楚, string Per = cp.GetPowerModelName(LoginID, ModelName);switch (Per) { case enmFuncSets.fsNotFunc.ToString(): ClientScript.RegisterStartupScript(this.GetType(), "GetPow", " window.parent.main.location = 'VoidPower.aspx';", true); break; case enmFuncSets.fsReadOnly.ToString(): Gv.Columns[ColIndex].Visible = false; break; default: ClientScript.RegisterStartupScript(this.GetType(), "GetPow", " window.parent.main.location = 'VoidPower.aspx';", true); break; }提示我应输入常量 string Per = cp.GetPowerModelName(LoginID, ModelName); enmFuncSets em= (enmFuncSets)Enum.Parse(typeof(enmFuncSets), "id");switch (em) { case enmFuncSets.fsNotFunc: break; } string Per = cp.GetPowerModelName(LoginID, ModelName); enmFuncSets em= (enmFuncSets)Enum.Parse(typeof(enmFuncSets), Per); switch (em) { case enmFuncSets.fsNotFunc: break; } enum enmFuncSets { fsNotFunc, fsReadOnly //... } private void button1_Click(object sender, EventArgs e) { string Per = cp.GetPowerModelName(LoginID, ModelName); enmFuncSets func = (enmFuncSets)Enum.Parse(typeof(enmFuncSets), Per); switch (func) { case enmFuncSets.fsNotFunc: ClientScript.RegisterStartupScript(this.GetType(), "GetPow", " window.parent.main.location = 'VoidPower.aspx';", true); break; case enmFuncSets.fsReadOnly: Gv.Columns[ColIndex].Visible = false; break; default: ClientScript.RegisterStartupScript(this.GetType(), "GetPow", " window.parent.main.location = 'VoidPower.aspx';", true); break; } } LZ可以考虑结贴了,不过,把GetPowerModelName方法的返回值类型直接定义为你想要得到的你自定义的Enum类型(而不是返回String)结构上是不是更好,那样像enmFuncSets func = (enmFuncSets)Enum.Parse(typeof(enmFuncSets), Per);这种代码也不需要try{}catch{}了。 求助。。。。 问一个小问题,有点急... 高手进来看看 如何通过C#来设置IIS6.0的ASP.NET的版本。 winform中直接修改datagrid的数据后如何更新数据库的数据 一道笔试题求解 HashTable 关于key的问题 求教 求助,一个关于线程习题的源代码?(要求按题目解决) 如何向新窗体传参数 求教如何用C#在不引用DLL文件的情况下压解Zip格式文件 未将对象引用设置到对象的实例。哪位能帮帮忙?已经找了几天还没找到问题 想设计一个c/s架构工程,求经验!!!!!
enum Gun
{
ShortGun,
MachineGun,
Rifle = 4
}string str;
str = Gun.Rifle.ToString(); // Rifle
str = Gun.Rifle.ToString("D"); // 10
enum Gun
{
ShortGun,
MachineGun,
Rifle = 10
} string str;
str = Gun.Rifle.ToString(); // Rifle
str = Gun.Rifle.ToString("D"); // 10
str = Gun.Rifle.ToString("X"); // 0000000A
你要转什么
没讲清楚,
string Per = cp.GetPowerModelName(LoginID, ModelName);
switch (Per)
{
case enmFuncSets.fsNotFunc.ToString():
ClientScript.RegisterStartupScript(this.GetType(), "GetPow", " window.parent.main.location = 'VoidPower.aspx';", true);
break;
case enmFuncSets.fsReadOnly.ToString():
Gv.Columns[ColIndex].Visible = false;
break;
default:
ClientScript.RegisterStartupScript(this.GetType(), "GetPow", " window.parent.main.location = 'VoidPower.aspx';", true);
break; }
提示我应输入常量
enmFuncSets em= (enmFuncSets)Enum.Parse(typeof(enmFuncSets), "id");
switch (em)
{
case enmFuncSets.fsNotFunc:
break;
}
enmFuncSets em= (enmFuncSets)Enum.Parse(typeof(enmFuncSets), Per);
switch (em)
{
case enmFuncSets.fsNotFunc:
break;
}
enum enmFuncSets
{
fsNotFunc,
fsReadOnly
//...
}
private void button1_Click(object sender, EventArgs e)
{
string Per = cp.GetPowerModelName(LoginID, ModelName);
enmFuncSets func = (enmFuncSets)Enum.Parse(typeof(enmFuncSets), Per); switch (func)
{ case enmFuncSets.fsNotFunc: ClientScript.RegisterStartupScript(this.GetType(), "GetPow", " window.parent.main.location = 'VoidPower.aspx';", true);
break;
case enmFuncSets.fsReadOnly:
Gv.Columns[ColIndex].Visible = false;
break;
default:
ClientScript.RegisterStartupScript(this.GetType(), "GetPow", " window.parent.main.location = 'VoidPower.aspx';", true);
break; }
}