相关疑难解决方法(0)

类型参数"T"与外部类型"..."中的类型参数同名

public abstract class EntityBase { ... }

public interface IFoobar
{
    void Foo<T>(int x)
        where T : EntityBase, new();
}

public interface IFoobar<T>
    where T : EntityBase, new()
{
    void Foo(int x);
}

public class Foobar<T> : IFoobar, IFoobar<T>
    where T : EntityBase, new()
{
    public void Foo(int x) { ... }

    void IFoobar.Foo<T>(int x) { Foo(x); }
}
Run Code Online (Sandbox Code Playgroud)

我收到编译器警告: Type parameter 'T' has the same name as the type parameter from outer type '...'

我尝试过:void IFoobar.Foo<U>(int x) { …

c# generics interface constraints explicit-interface

17
推荐指数
3
解决办法
1万
查看次数