繁体   English   中英

IEnumerable<T> 与委托的返回值具有相同的类型

[英]IEnumerable<T> having the same type as the return value of delegate

我有一个这样声明的函数:

        public static IEnumerable<T> MyMethod<T>(IEnumerable<T> s1,
                                                        IEnumerable<T> s2,
                                                        Func<T, T> funcDel)
    { ... }

我需要将此函数用作参数:

            Func<char, bool> sampleF = (ch) => { //stuff }

但是 IDE 会返回错误,因为无法推断类型参数。 我不确定我做错了什么。

如何设置我的方法以返回相同类型的委托?

您已将funcDel声明为Func<T, T> 两个T是一样的。 但是, sampleF的类型是Func<char, bool> <char, bool>是两个不同的T

如果您希望它们不同,则需要IEnumerable<T2> MyMethod<T1, T2>Func<T1,T2>类型的funcDel

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM