相关疑难解决方法(0)

无法从具有多个返回的"选择"中的用法推断出C#类型参数

我不认为我做了太深奥的事情,但我没有看到任何其他问题.

下面的代码(我把它简化为要点)在C#4中生成了一个编译器错误.但是,类型参数应该是显而易见的 - 有一个最大的公分母("A类"),它也明确定义在方法"Frob"的返回类型.编译器是否应该在lambda表达式中创建所有返回类型的列表,创建一个祖先树来查找它们的共同祖先,然后将它与包含方法的预期返回类型进行协调?

无法从用法推断出方法'System.Linq.Enumerable.Select(System.Collections.Generic.IEnumerable,System.Func)'的类型参数.尝试显式指定类型参数.

using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

namespace Sample
{
    public abstract class A
    {
        private A(int index) { /* ... */ }

        public sealed class A1 : A
        {
            public A1(string text, int index)
                : base(index)
            { /* ... */ }
        }

        public sealed class A2 : A
        {
            public A2(int index)
                : base(index)
            { /* ... */ }
        }

        private static Regex _regex = new Regex(@"(to be)|(not to be)");
        public static IEnumerable<A> Frob(string frobbable) …
Run Code Online (Sandbox Code Playgroud)

c# linq generics inheritance

12
推荐指数
2
解决办法
3万
查看次数

标签 统计

c# ×1

generics ×1

inheritance ×1

linq ×1