什么是动作<字符串>? [英] What is Action<string>?

查看:30
本文介绍了什么是动作<字符串>?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是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

    这篇关于什么是动作&lt;字符串&gt;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    相关文章
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆