Enum.GetNames 
Enum.GetValues

解决方案 »

  1.   


    enum Gun
    {
       ShortGun,
       MachineGun,
       Rifle = 4
    }string str;
    str = Gun.Rifle.ToString();        // Rifle
    str = Gun.Rifle.ToString("D");     // 10
      

  2.   

    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
      

  3.   

    enum  是枚举 
    你要转什么  
    没讲清楚,
      

  4.   

     
    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;            }
    提示我应输入常量
      

  5.   

    string Per = cp.GetPowerModelName(LoginID, ModelName); 
    enmFuncSets em= (enmFuncSets)Enum.Parse(typeof(enmFuncSets), "id");
    switch (em) 
                { 
                         
                    case enmFuncSets.fsNotFunc:
                       break;
                } 
      

  6.   

    string Per = cp.GetPowerModelName(LoginID, ModelName);  
    enmFuncSets em= (enmFuncSets)Enum.Parse(typeof(enmFuncSets), Per); 
    switch (em)  
                {  
                          
                    case enmFuncSets.fsNotFunc: 
                       break; 
                }  
      

  7.   


        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;        } 
        }
      

  8.   

    LZ可以考虑结贴了,不过,把GetPowerModelName方法的返回值类型直接定义为你想要得到的你自定义的Enum类型(而不是返回String)结构上是不是更好,那样像enmFuncSets func = (enmFuncSets)Enum.Parse(typeof(enmFuncSets), Per);这种代码也不需要try{}catch{}了。