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

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

posted on 2014-03-20 20:20  yuthreestone  阅读(193)  评论(0编辑  收藏  举报

导航