如何虚方法在C#中的工作? [英] How do virtual methods work in C#?

查看:125
本文介绍了如何虚方法在C#中的工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道在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.

这篇关于如何虚方法在C#中的工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆