最近本人刚开始学习C#,现在在枚举这里遇到一点问题,麻烦各位高手帮忙分析!namespace 枚举

 class Program
  {
    enum sanguoName:byte
    {
      东吴=1
       西蜀
    曹魏
      } 
       static void Main(string[] args)
    {
     sangguoName newSanguoName=sanguoName.西蜀;
   byte sanguoduiwu;
     string sanguoNameString;
     Console.WriteLine("选择的国家是:{0}",newSanguoName);
     sanguoDuiwu=(byte)newSanguoName;
     newSanguoName=(sanguoName)sanguoDuiwu;
     Console.WriteLine("选择的国家是:{0}",newSanguoName);
     sanguoNameString=Convert.ToString(newSanguoName);
     Console.WriteLine("选择的队伍是:{0}",newSanguoName);
     Console.WriteLine("选择的队伍代表的国家是:{0}",sanguoNameString);
     Console.ReadKey();
    }
特别是对红色字体部分解释下,谢谢1

解决方案 »

  1.   

    sanguoDuiwu=(byte)newSanguoName; // 将枚举转换为 bytenewSanguoName=(sanguoName)sanguoDuiwu;  // 将 byte 转换为枚举
      

  2.   

    因为枚举定义的是Byte,所以转型成枚举的类型。
      

  3.   


         
    sanguoDuiwu=(byte)newSanguoName; 
     enum sanguoName:byte 因为你继承了byte
    newSanguoName=(sanguoName)sanguoDuiwu;  
    差不多这个意思。默认转换成sanguoName
    Enum.Parse(typeof(sanguoName), "西蜀");希望没有误导你