Interface with generic parameter vs Interface with generic methods

前端 未结 4 1168
别那么骄傲
别那么骄傲 2020-12-08 02:34

Let\'s say I have such interface and concrete implementation

public interface IMyInterface
{
    T My();
}

public class MyConcrete : IMyInterface&l         


        
4条回答
  •  孤街浪徒
    2020-12-08 02:56

    when you write the Generic Method the Definition is for keeping the placeholder. Actual Type comes into picture when you call the method. so instead you should write

    public T My()
    {
        throw new NotImplementedException();
    }
    

    and when you call the method you can use the string there.

提交回复
热议问题