Why C# doesn't allow inheritance of return type when implementing an Interface

后端 未结 6 672
一生所求
一生所求 2020-11-28 14:24

Is there any rational reason why the code below is not legal in C#?

class X: IA, IB
{
    public X test() // Compliation Error, saying that X is not IB
    {         


        
6条回答
  •  遥遥无期
    2020-11-28 14:49

    This can help http://geekswithblogs.net/abhijeetp/archive/2010/01/10/covariance-and-contravariance-in-c-4.0.aspx You can use the "out" keyword

提交回复
热议问题