接口编译 [英] Interface Compilation
问题描述
有关C#接口的快速问题.我想知道它们在编译和使用汇编方面有多精确.
Quick question regarding interfaces in C#. I was wondering how exactly they are compiled and used assembly wise.
我想象接口没有被编译成汇编.我认为接口定义是在编译时编译到类中的,因此接口本质上是一种高级语言概念.
I imagine interfaces are not compiled into assembly. I imagine that the interface definitions are compiled into the class at compile time, so interfaces are essentially a high level language concept.
有人可以告诉我我的想法是否正确吗?我已经得出了这个结论,因为我已经阅读到接口没有实例化,它们是它们自己的实体.但是,另一方面,我也读到它们是引用类型,这使我感到困惑,因为这表明它们已实例化?
Could someone please tell me if I am correct/incorrect in thinking this? I came to this conclusion as I have read that interfaces are not instantiated, they are their own entity. On the other hand however, I have also read that they are reference types which confuses me as that would suggest that they are instantiated?
非常感谢.
推荐答案
我只是反汇编了一个仅包含接口的小程序:
I just disassemble a small program containing just an interface:
public interface IFoo {
void Foo();
}
这就是我得到的:
.class interface public auto ansi abstract IFoo {
// method line 3
.method public virtual hidebysig newslot abstract
instance default void Foo () cil managed
{
// Method begins at RVA 0x0
} // end of method IFoo::Foo
} // end of class IFoo
因此,如果按大会的意思是MSIL,那么答案是肯定的,它们被视为类.
So, if by Assembly you mean MSIL, the answer would be yes, they are treated like classes.
这篇关于接口编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!