lambda及多线程

1.lambda表达式

delegate int caculate(int x, int y);
delegate int caculate2();

caculate c = new caculate(add);
Console.WriteLine(c(1,2));

caculate2 c2 = () => { return 10; } ;
Console.WriteLine(c2());

2.Func委托

public delegate TResult Func(T arg);

泛型T为输入参数,泛型TResult为输出结果

Func function = p => p + 10+"" ;
Console.WriteLine(function(10));

3.带参数(参数必须是Object)和不带参数多线程

Thread t1 = new Thread(new ParameterizedThreadStart(tfunc));带参数
//Thread t2 = new Thread(new ThreadStart(tfunc));

t.Start(10);

tfunc(object o)    参数为Obeject

你可能感兴趣的:(C#,.Net)