147-结构体
定义结构
struct <typeName>{
<memberDeclarations>
}
其中<memberDeclarations>是结构体的成员,每个成员的声明如下
<type> <name>;
表示一个游戏物体(主角或者敌人)的坐标,需要三个小数
struct Vector3{
float x;
float y;
float z;
}
定义结构
struct <typeName>{
<memberDeclarations>
}
其中<memberDeclarations>是结构体的成员,每个成员的声明如下
<type> <name>;
struct Vector3{ float x; float y; float z; } Vector3 vec; vec.x=34;
定义一个路径结构,路径由方向和距离组成,假定方向只能是东西南北:
enum Direction { West, North, East, South } struct Path { public float distance; public Direction dir; } class Program { static void Main(string[] args) { Path path1; path1.dir = Direction.East; path1.distance = 1000; } }