首页 > 学院 > 开发设计 > 正文

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

2019-11-17 03:16:38
字体:
来源:转载
供稿:网友

【转载】#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);    // Petulant3 4 m = Mood.Crabby;5 int i = (int)m;6 Console.WriteLine(i);    // 0

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


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表