C# 使用枚举获取对应的数组值时

using System;

enum Move
{
    walk,
    run
}
class Program
{
    static float[] speedAry = 
        {
            50.0f,
            200.0f
            
        };

    public static Move move = Move.walk;

    static void Main(string[] args)
    {
        //当你要使用枚举,获取对应的数组值得时候.

        //简洁写法
        Console.WriteLine("走的速度: " + speedAry[(int)Move.walk]);
        Console.WriteLine("跑的速度: " + speedAry[(int)Move.run]);

        Console.WriteLine("

");
        
        //复杂写法
        switch (move) 
        {
            case Move.walk:
                Console.WriteLine("走的速度:" + speedAry[0]);
                break;
            case Move.run:
                Console.WriteLine("跑的速度:" + speedAry[1]);
                break;
        }

        Console.ReadLine();
    }
}
原文地址:https://www.cnblogs.com/plateFace/p/5041246.html