枚举 and 结构体
前言
- 枚举类型(enum): 人为限定取值范围的整数
- 结构体类型(struct): 值类型,可装/拆箱;可实现接口,不能派生自类/结构体;不能有显示无参构造器
一、枚举类型
using System;
namespace InterfaceTest
{
internal class Program
{
public static void Main(string[] args)
{
Person person = new Person();
person.level = Level.Employee;
Person boss = new Person();
boss.level = Level.Bosss;
System.Console.WriteLine(boss.level > person.level);
}
}
enum Level
{
Employee,
Manager,
Bosss,
BigBoss,
}
class Person
{
public int ID {
get; set; }
public string Name {
get; set; }
public Level level {
get; set; }