switch expression - 用lamda expression 寫 Fibonacci

原本是這樣的:

 class Program
    {
        public static int fib(int i){
            if (i <= 2) return 1;
            return fib(i -2) + fib(i - 1);
        }


        static void Main(string[] args)
        {
            Console.WriteLine(fib(20));
        }
    }

變成這樣:

int fib(int i) =>
    i switch
    {
        int when i <= 2 => 1,
        _ => fib(i -2) + fib(i - 1)
    };

System.Console.WriteLine(fib(20));