首页 > 其他 > 详细

【转载】#457 Converting Between enums and their Underlying Type

时间:2014-03-21 04:55:59      阅读:341      评论:0      收藏:0      [点我收藏+]

When you declare an enum, by default each enumerated value is represented internally with an int. (System.Int32 - 4 bytes). You can convert between values of the underlying type and enum values using an explicit cast. Because an enum is represented by an int by default, you can convert between integers and enum values.

1 Mood m = (Mood)2;
2 Console.WriteLine(m);    // Petulant
3 
4 m = Mood.Crabby;
5 int i = (int)m;
6 Console.WriteLine(i);    // 0

 原文地址:#457 Converting Between enums and their Underlying Type

【转载】#457 Converting Between enums and their Underlying Type,布布扣,bubuko.com

【转载】#457 Converting Between enums and their Underlying Type

原文:http://www.cnblogs.com/yuthreestone/p/3614538.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!