c# lambda表达式学习(2)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main()
        {
            //1、lambda定义. 
            Func lambda = x => x;
            Console.WriteLine(lambda("my lambda."));

            //2、lambda参数 
            Func square = (double x, double y) => x * y;
            Console.WriteLine(square(1, 2));

            //可以省略参数的类型
            Func cube = (x, y, z) => x * y * z;
            Console.WriteLine(cube(2, 4, 6));

            //3、调用外部参数 
            int val = 4;
            Func fun = (x, y, z) => x + y + z + val;
            Console.WriteLine(fun(1, 2, 3));
            Console.Read();
        }
    }
}

你可能感兴趣的:(lambda表达式,c#,lambda,lambda表达式)