如何虚方法在C#中的工作?方法、工作

2023-09-04 08:37:36 作者:梦醒人散丶

我知道在C ++中有vpointer和虚函数表。 虚拟函数表是方法指针以在类的虚拟方法的列表。 类的每个实例都具有一个指针到表中,当我们称从实例的虚拟方法,该方法被使用。

I know in C++ there are vpointer and vtable. The virtual function table is a list of method pointers to the virtual methods in the class. Each instance of a class has a pointer to the table, which is used when we call a virtual method from the instance.

我想知道这是如何实现在C#中。据我所知虚表的概念是相同的。但对于vpointer是的GetType()来代替。

I want to know how this implemented in C#. As I know the concept of virtual tables are the same. But what about vpointer is GetType() is used instead.

我会AP preciate尽可能多的细节尽可能。 谢谢。

I would appreciate as much details as possible. Thank you.

推荐答案

V表位于C一种可能的方法++,它们的没有的由C ++标准规定。该方法.NET使用明确符合CLI和C#中公布的标准,但没有规定实施细则(并有可能改变)。

Vtables are one possible approach in C++, they are not mandated by the C++ standard. The approach .NET uses clearly meets the published standards for the CLI and C#, but the implementation details are not specified (and could potentially change).

您可以推断从接口,覆盖成员和新成员的工作方式的一些细节。

You can infer some details from the way that interfaces, overridden members and "new" members work.

你为什么想知道?如果你有一个具体的问题,那么说明这个问题将允许其他人直接解决。

Why do you want to know this? If you have a specific problem then stating the problem will allow others to address that directly.