using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace lambda
{
class Program
{
static void Main(string[] args)
{
Func<int, int, int> a = new Func<int, int, int>((a1, b1) => { return a1 + b1; });//1
Func<int, int, int> b =(a1, b1) => { return a1 + b1; };//2
Func<int, int, int> c =(a1, b1) => { return a1 + b1; };
c = (a1, b1) => { return a1 * b1; }; //3
Func<int, int, int> d = new Func<int, int, int>((int a1,int b1) => { return a1 + b1; });//4
int res=calculate<int>((a1, b1) => { return a1 + b1; }, 100, 200);//5,<int>可省
}
}
static T calculate<T>(Func<T,T,T>func,T a,T b)
{
T res = func(a, b);
return res;
}
}
lambda表达式的几种写法
最新推荐文章于 2023-12-05 20:54:05 发布