张德长

导航

C#枚举-通过值获取名字,通过名称获取值

public enum ProtoType
{
    Move = 1,
    Enter = 2,
    Leave = 3,
    Attack,
    Die,
}

        print("ProtoType.Move:" + ProtoType.Move);
        print("ProtoType.Move.ToString():" + ProtoType.Move.ToString());
        print("Enum.GetName(typeof(ProtoType),3):" + Enum.GetName(typeof(ProtoType), 3));
        print("(ProtoType)(1):" + (ProtoType)(1));
        print("(ProtoType)(3):" + (ProtoType)(3));
        print("(ProtoType)(8):" + (ProtoType)(8));
        var arry = Enum.GetValues(typeof(ProtoType));
        foreach (var item in arry) { print(item); }

posted on 2022-03-29 17:46  张德长  阅读(1874)  评论(0编辑  收藏  举报