【问题标题】:IEnumerable<T> having the same type as the return value of delegateIEnumerable<T> 与委托的返回值具有相同的类型
【发布时间】:2022-06-15 04:45:56
【问题描述】:

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

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

我需要使用这个函数作为参数:

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

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

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

【问题讨论】:

  • 您已声明Func&lt;T, T&gt;。两个T 是相同的T&lt;char, bool&gt; 是两个不同的 T。如果你想让它们与众不同,你需要IEnumerable&lt;T1, T2&gt; MyMethod&lt;T1, T2&gt;

标签: c#


猜你喜欢
  • 1970-01-01
  • 2013-08-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多