Type parameter 'T' has the same name as the type parameter from outer type '…'

前端 未结 3 1208
执念已碎
执念已碎 2021-01-07 19:06
public abstract class EntityBase { ... }

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

public interface IFoobar<         


        
3条回答
  •  我在风中等你
    2021-01-07 19:27

    You can do one of two things:

    1. Ignore the warning and make both types T.
    2. Do a run-time check and throw an exception:

      if (typeof(T) != typeof(U)) throw Exception("Not the same type");
      

    As others have stated, perhaps you need to rethink the way you are designing your interfaces.

提交回复
热议问题