枚举类型:
enum Position
{
x,
y,
z
}
static void Main(String[ ] args)
{
Position pos = Position.x; // x为Position里的属性
Console.WriteLine(pos);
int num = (int) pos;//显示转换
Console.WriteLine(num); //结果为0
}
枚举类型默认为是int类型,并默认为从0,1,2,3...递增排序,也可为属性赋值,也可改变枚举类型的int类型(如将其换成byte来减少内存的消耗)如:
enum Position:byte
{
x = 100,
y = 200,
z = 134
}

结构体:
stuct Student
{
public String name;
public String school;
}
static void Main(String[ ] args)
{
Student tom;
tom.name = "Tom";
tom.school = "ZK";
Console.WriteLine(tom.name + tom.school);
}
结构体可以将有限个不同类型的属性变量组合在一起,与枚举类型不同之处是枚举类型内的都是同类型的属性变量,并且结构体可以有结构函数。如:
stuct Student
{
public String name;
public String school;
public String info(int time)
{
return name +" "+ school + time;
}
}
static void Main(String[ ] args)
{
Student tom;
tom.name = "Tom";
tom.school = "ZK";
int mytime = 10;
Console.WriteLine(tom.info(mytime));
}