using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace _2023_0624_1117枚举类型
{
enum State2 { 站立, 走, 跑, 攻击, 被攻击 };//state状态
class Program
{
//static int state;//状态
//站立,走。跑。攻击,被攻击
enum State { Stand, Go,Run,Attack,Attacked };//state状态
//bool true flase
static void Main(string[] args)
{
#region 一般写法
//state = 0;//站立
//state = 1;//走
//state = 2;//跑
//state = 3;//攻击
//state = 4;//被攻击
#endregion
#region 枚举类型:可以卸载类的里边也可以卸载类的外面
State state =new State();//实例化:实例化以后变量存在默认值
state = State.Go;
State state2 = new State();
state2 = State.Attack;
Console.WriteLine("state:"+ state);
Console.WriteLine("state2:"+ state2);
//State state3;//没有赋值会报错
//Console.WriteLine(state3);
State state4 = new State();
Console.WriteLine("state4:"+state4);
#endregion
}
}
}
1C#基础-枚举
于 2023-09-07 14:25:26 首次发布