微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

c# – .Net接口继承编译

为什么是这样 :

public interface IServiceRecherche<T,U>
                    where T : IEntite
                    where U : ICritereRecherche
{
    IList<T> Rechercher(U critere);
}

public interface IServiceRechercheUnite :
                        IServiceRecherche<IUnite,ICritereRechercheUnite>,{}

不同于 :

public interface IServiceRechercheUnite                             
{
    IList<IUnite> Rechercher(ICritereRechercheUnite critere);
}

编译时?

使用第一个接口编译的应用程序无法识别第二个接口.我知道它们在代码中不一样,但最终在执行期间为什么它们不一样?

解决方法

从CLR的角度来看,这些是不同的类型,因为第一个是封闭泛型类型,继承自IServiceRecherche< T,U>.

but in the end during execution why aren’t they the same

原因是相同的,如下:

public MyClass1
{
  public int MyProperty { get; set; }
}

public MyClass2
{
  public int MyProperty { get; set; }
}

它们只是一个不同类型的声明,尽管有类似的成员声明.

CLR不能这么想:“啊,MyClass1和MyClass2是相同的.让我们把它们视为同一类型”.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐