using System;
namespace num05
{
  enum color:byte
  {
   red, 
   orange, 
   yellow, 
   green, 
   blue, 
   indigo, 
   purple, 
   black, 
   white, 
  } class test
 {
  static void Main(string[] args)
  {  color myColor_;
  int myColor=1;
  myColor=Convert.ToByte(Console.ReadLine());
  myColor_=myColor;
  Console.WriteLine("{0}",myColor_);
  }
 } 
}
Microsoft (R) Visual C# 2005 Compiler version 8.00.50727.26
for Microsoft (R) Windows (R) 2005 Framework version 2.0.50727
Copyright (C) Microsoft Corporation 2001-2005. All rights reserved.num05.cs(25,12): error CS0266: Cannot implicitly convert type 'int' to
        'num05.color'. An explicit conversion exists (are you missing a cast?)大家帮看看什么问题!

解决方案 »

  1.   

    myColor=Convert.ToByte(Console.ReadLine());
    变量 myColor 不是int型的吗 注掉他
    下一行改为:
       myColor_ = (color)myColor;
    编译通过,无错误
      

  2.   

    using System;
    namespace num05
    {
        enum color : byte
        {
            red,
            orange,
            yellow,
            green,
            blue,
            indigo,
            purple,
            black,
            white,
        }    class test
        {
            static void Main(string[] args)
            {            color myColor_;
                int myColor = 1;
                myColor = Convert.ToByte(Console.ReadLine());
                myColor_ = (color)Enum.Parse(typeof(color),myColor.ToString());
                Console.WriteLine("{0}", myColor_);
            }
        }
    }
    这样就正确了