[英]Why does the C# compiler explicitly declare all interfaces a type implements?
The C# compiler seems to explicitly note all interfaces it, and its base classes implement. C#编译器似乎明确地记下了它的所有接口,并且它的基类实现了。 The CLI specs say that this is not necesary.
CLI规范说这不是必要的。 I've seen some other compilers not emit this explicitly, and it seems to work fine.
我已经看到其他一些编译器没有明确地发出它,它似乎工作正常。 Is there any difference or reason the C# does this?
C#是否有这样的差异或原因?
The MSIL that the C# at the bottom generates for B is: 底部的C#为B生成的MSIL是:
.class private auto ansi beforefieldinit B
extends A
implements IAdvanced,
ISimple
It shouldn't need to specify ISimple, because A implements it as does IAdvanced. 它不需要指定ISimple,因为A和IAdvanced一样实现它。 C# code:
C#代码:
interface ISimple {
int Basic { get; }
int Zero { get; }
}
interface IAdvanced : ISimple {
string Major { get; }
}
class A : ISimple {
int ISimple.Basic {
get { return 1; }
}
int ISimple.Zero {
get{ return 0;}
}
}
class B : A, IAdvanced {
string IAdvanced.Major {
get { return "B"; }
}
}
I don't think we can know any definitive answer here, unless we have the compiler developers drop in. However, we can guess about the reasons. 我不认为我们可以在这里知道任何确定的答案,除非我们让编译器开发人员介入。但是,我们可以猜测原因。 It could be:
它可能是:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.