请教!枚举和结构的一个案例问题, using System; using System.Collections.Generic; using System.Text;
namespace 结构案例 { enum orientation : byte //定义orientation枚举 { north = 1, south = 2, east = 3, west = 4, } struct route //定义了结构 { public orientation direction; //通过关键字 public 定义了枚举新的变量 public double distance; //定义double 变量 } class Program {
static void Main(string[] args) { route myRoute; //结构定义新变量 int myDirection = -1; double myDistance; Console.WriteLine("1> North\n 2> South\n 3> East\n 4>West"); do { Console.WriteLine("select a direction:"); myDirection = Convert.ToInt32(Console.ReadLine());//转换类型 } while ((myDirection < 1) || (myDirection > 4)); Console.WriteLine("input a distance;"); myDistance = Convert.ToDouble(Console.ReadLine());//转换类型 myRoute.direction = (orientation)myDirection; myRoute.distance = myDistance; Console.WriteLine(" myRoute specifies a direction of{0} and a" + "distance of {1}", myRoute.direction, myRoute.distance); Console.ReadKey();
} } }
------解决方案--------------------
------解决方案-------------------- int myDirection = -1; myDirection = Convert.ToInt32(Console.ReadLine());//转换类型