如何描述Action< T>代表返回一个值(非void)?

编程入门 行业动态 更新时间:2024-10-10 12:20:44
本文介绍了如何描述Action< T>代表返回一个值(非void)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

Action< T> delegate返回void。有没有其他内置的代理返回非空值?

The Action<T> delegate return void. Is there any other built-in delegate which returns non void value?

推荐答案

是的。 Func 返回指定为最终泛型类型参数的类型,这样 Func< int> code> int 和 Func< int,string> 接受一个整数并返回一个字符串。示例:

Yes. Func<> returns the type specified as the final generic type parameter, such that Func<int> returns an int and Func<int, string> accepts an integer and returns a string. Examples:

Func<int> getOne = () => 1; Func<int, string> convertIntToString = i => i.ToString(); Action<string> printToScreen = s => Console.WriteLine(s); // use them printToScreen(convertIntToString(getOne()));

更多推荐

如何描述Action&lt; T&gt;代表返回一个值(非void)?

本文发布于:2023-11-09 08:06:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1571824.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:代表   amp   Action   lt   void

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!