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("\n\n");
        
        //复杂写法
        switch (move) 
        {
            case Move.walk:
                Console.WriteLine("走的速度:" + speedAry[0]);
                break;
            case Move.run:
                Console.WriteLine("跑的速度:" + speedAry[1]);
                break;
        }

        Console.ReadLine();
    }
}

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-30
猜你喜欢
  • 2022-12-23
  • 2021-09-20
  • 2022-12-23
  • 2022-12-23
  • 2021-12-09
  • 2022-12-23
相关资源
相似解决方案