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

解决方案 »

  1.   

     int myDirection = -1; myDirection = Convert.ToInt32(Console.ReadLine());//转换类型 上面定义了类型后,下面赋值,能这样子吗??
    -1 = Convert.ToInt32(Console.ReadLine());// ????
      

  2.   

    -1 = Convert.ToInt32(Console.ReadLine());// 直接这样写可以?
    -1是值,左边跟的是变量啊,我怎么就没看到有-1=...的
    这是先int myDirection = -1;,然后再myDirection = Convert.ToInt32(Console.ReadLine())的啊
      

  3.   

    应该是把Convert.ToInt32(Console.ReadLine())直接又赋给了myDirection了吧?
      

  4.   

    可以啊,不就是给myDirection = Convert.ToInt32(Console.ReadLine());//转换类型 
    它被重新赋值了。你在这里进行了字符串和整型的转换嘛...对啊!
      

  5.   

    int myDirection = -1;
    myDirection = Convert.ToInt32(Console.ReadLine());//转换类型LZ分明误会了这两句的含义。
    -1只是myDirection的初始值。你可以不给它赋初值,
    直接:int myDirection;(当然,赋成其他值也可以,比如0.)
    第二句才给它赋值:myDirection = Convert.ToInt32(Console.ReadLine());
      

  6.   


    myDirection = Convert.ToInt32(Console.ReadLine());//转换类型 
    时 
    myDirection 是一个int型的变量  这个myDirection 的初始值是"-1" 而非-1 = Convert.ToInt32(Console.ReadLine());
    楼主理解错误
      

  7.   

    你确定可以这样写?
    -1 = Convert.ToInt32(Console.ReadLine()); ???????
    LZ问的是这种写法