A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 胡杰震 中级黑马   /  2012-3-25 17:38  /  1910 人查看  /  1 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

enum  oriention:byte
{north=1,
south=2,
}
在main方法中调用
oriention      myDirection=oriention.north;
然后输出myDirection,返回的值是north,为什么返回的不是1呢?

评分

参与人数 1技术分 +1 收起 理由
郑文 + 1

查看全部评分

1 个回复

倒序浏览
他是一个枚举类型。
   enum oriention : byte
        {
            north = 1,
            south = 2,
        }

要得到1有两种方法:
  一: oriention ori = oriention.north;
       byte byt = (byte)ori;//强制转换
   Console.WriteLine(byt.ToString());
  二:  oriention ori = oriention.north;
        Console.WriteLine(ori.GetHashCode());
要得到2:
  一: oriention ori = oriention.south;
       byte byt = (byte)ori;//强制转换
       Console.WriteLine(byt.ToString());

评分

参与人数 1技术分 +2 收起 理由
郑文 + 2

查看全部评分

回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马