本文介绍了如何描述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< T>代表返回一个值(非void)?
发布评论