2008/08/12

C#结构





以下是一个示例:

using System;

using System.Collections.Generic;

using System.Text;


namespace ConsoleApplication1

{

enum Direction : byte

{

north=1, //注意这里的标点

south=2,

east=3,

west=4

}


struct route

{

public Direction MyDirection;

public double Distance;

}


class Program

{

static void Main(string[] args)

{

route MyRoute;

int OneDirection;

double MyDistance;

Console.WriteLine("1) North\n2) South\n3) East\n4) West");

do

{

Console.WriteLine("Please select a direction :");

OneDirection=Convert.ToInt32(Console.ReadLine());

}while((OneDirection<1)(OneDirection>4));


Console.WriteLine("Input a distance :");

MyDistance = Convert.ToDouble(Console.ReadLine());

MyRoute.MyDirection = (Direction)OneDirection;

MyRoute.Distance = MyDistance;

Console.WriteLine("MyRoute specifies a direction of {0} and a distance of {1}",MyRoute.MyDirection,MyRoute.Distance);

Console.ReadKey();

}

}

}

没有评论: