Func<T, TResult> 委托:封装一个具有一个参数并返回 TResult 参数指定的类型值的方法。
Func<string, string> toUpper = x => x.ToUpper();
string[] words = { "aaaa","bbbb","cccc","dddd"};
IEnumerable<string> toWords=words.Select(toUpper);
foreach (var m in toWords)
Console.WriteLine(m);
Action<T>泛型委托:封装一个方法,该方法只采用一个参数并且不返回值.
static void Main(string[] args)
{
Action<User,int> actions = (x, y) => x.SetUser(y);
User u=new User();
actions(u, 1);
Console.Read();
}
public class User
{
public void SetUser(int userId)
{
Console.WriteLine(userId);
}
}