PS:注释和讲解全在代码中
1. 枚举与结构体
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace C4_程序设计
{
public enum Pro
{
战士,法师,牧师,圣骑士,盗贼
}
public struct Player
{
public Pro JS;
public int HP, MP; //所有变量在声明前不能忽略public,这和C++不一样(C++的结构体默认public)
public double att, def;
}
public struct Point
{
public int x;
public int y;
}
class 枚举与结构体
{
static void Main()
{
Pro you = Pro.战士;
Console.WriteLine(you);
Player me = new Player(); //结构体简单定义/初始化
me.JS = Pro.法师;
me.HP = 10000;
me.att = 100;
me.def = me.att/3;
Console.WriteLine(me.def);
Point[] s = new Point[7]; //结构体数组的定义
for (int i = 0; i < s.Length; i++)
{
s[i].x = i;
s[i].y = i * 2;
}
for (int i = 0; i < s.Length; i++)
{
Console.Write("{0},{1}", s[i].x, s[i].y);
Console.Write("\n");
}
}
}
}