using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace learn_lambda2
{
internal class Program
{
static void Main(string[] args)
{
// 单行, 无参数, 无返回值
Action action = () => { Console.WriteLine("hello world"); };
action();
// 多行, 两个参数, 无返回值
Action<int, string> action1 = new Action<int, string>((a, b)=> {
a += a;
Console.WriteLine($"{a} + {b}");
});
action1(123, "123");
// 单行, 无参数, 有返回值
Func<int> action2 = () => { return 123; };
Console.WriteLine(action2());
// 多行, 两个参数, 有返回值
Func<int, string, int> action3 = new Func<int, string, int>((a, b) =>
{
a += a;
return Convert.ToInt32(b) + a;
});
Console.WriteLine(action3(123, "123"));
Console.ReadKey();
}
}
}
执行结果
hello world
246 + 123
123
369