FUNC< T>与出参数 [英] Func<T> with out parameter

查看:231
本文介绍了FUNC< T>与出参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以通过一个方法的输出参数为Func键?

Can I pass a method with an out parameter as a Func?

public IList<Foo> FindForBar(string bar, out int count) { }

// somewhere else
public IList<T> Find(Func<string, int, List<T>> listFunction) { }

函数功能需要一个类型,这样出来不会编译那里,并呼吁listFunction需要一个int,也不允许在了。

Func needs a type so out won't compile there, and calling listFunction requires an int and won't allow an out in.

有没有办法做到这一点?

Is there a way to do this?

推荐答案

REF 退出不是的一部分类型参数的定义,所以你不能使用内置的 Func键委托传递 REF 退出参数。当然,你可以声明自己的代理,如果你想要的:

ref and out are not part of the type parameter definition so you can't use the built-in Func delegate to pass ref and out arguments. Of course, you can declare your own delegate if you want:

delegate V MyDelegate<T,U,V>(T input, out U output);

这篇关于FUNC&LT; T&GT;与出参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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