是每一个抽象的虚函数在C#中,有什么看法? [英] Is every abstract function virtual in C#, in general?

查看:100
本文介绍了是每一个抽象的虚函数在C#中,有什么看法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找堆栈溢出问题的 是什么抽象的函数和虚函数的区别? 的,我想知道每一个抽象的功能是否应被认为是在C#或一般的虚拟函数?

I was looking at Stack Overflow question What is the difference between abstract function and virtual function?, and I was wondering whether every abstract function should be considered to be a virtual function in C# or in general?

我有点受必须覆盖不解/你可以重写对这个问题的反应。不是一个C#程序员,我倾向于认为抽象的功能只,而抽象函数的定义是虚函数,因为你必须提供至少一个,但还可以提供多种实现沿层次编译时的概念。

I was a bit puzzled by the "you must override/you may override" responses to that question. Not being a C# programmer, I tend to think that abstract functions are a compile-time concept only, and that abstract functions are virtual functions by definition since you must provide at least one but can provide multiple implementations further down the hierarchy.

虚拟函数有一个编译时间维度也一样,你不能忽略非虚函数,但它们大多运行时的概念,因为它是公正的选择根据实际接收器的正确方法实现的。

Virtual functions have a compile-time dimension too, in that you cannot override a non-virtual function, but they are mostly a runtime concept since it is "just" the selection of the correct method implementation based on the actual receiver.

推荐答案

是的。从 C#第10.6.6 3.0规范

当一个实例方法的声明
包括一个抽象的修改,即
方法说是一个抽象的
法。虽然抽象方法是
也隐含一个虚拟的方法,
不能修改虚拟的。

When an instance method declaration includes an abstract modifier, that method is said to be an abstract method. Although an abstract method is implicitly also a virtual method, it cannot have the modifier virtual.

这篇关于是每一个抽象的虚函数在C#中,有什么看法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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