枚举扩展方法

public static class EnumExtensions
2{
3    public static int GetValue(this Enum @enum)
4    {
5        return Convert.ToInt32(@enum);
6    }
7}
8
9class Program
10{
11    static void Main()
12    {
13        int intValue = MyEnum.Value1.GetValue(); // intValue将会是0
14        Console.WriteLine(intValue); // 输出: 0
15    }
16}
posted @ 2024-07-17 09:33  China Soft  阅读(2)  评论(0编辑  收藏  举报