什么是Action<string>
,怎么用?
Action
是一个标准委托,有 1 到 4 个参数(.NET 4 中为 16 个)并且不返回值.它用于表示一个动作.
Action
is a standard delegate that has one to 4 parameters (16 in .NET 4) and doesn't return value. It's used to represent an action.
Action<String> print = (x) => Console.WriteLine(x);
List<String> names = new List<String> { "pierre", "paul", "jacques" };
names.ForEach(print);
还有其他预定义的委托:
There are other predefined delegates :
谓词
,有一个参数并返回一个布尔值的委托.
Predicate
, delegate that has one parameter and returns a boolean.
Predicate<int> predicate = ((number) => number > 2);
var list = new List<int> { 1, 1, 2, 3 };
var newList = list.FindAll(predicate);
Func
是更通用的一个,它有 1 到 4 个参数(.NET 4 中为 16 个)并返回一些东西
Func
is the more generic one, it has 1 to 4 parameters (16 in .NET 4) and returns something
这篇关于什么是动作<字符串>?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!