为什么C#实现方法作为非虚默认? [英] Why C# implements methods as non-virtual by default?

查看:267
本文介绍了为什么C#实现方法作为非虚默认?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

与Java不同,为什么C#的治疗方法,因为默认情况下非虚函数?是它更可能是一个性能问题,而不是其它可能的结果

Unlike Java, why does C# treat methods as non-virtual functions by default? Is it more likely to be a performance issue rather than other possible outcomes?

我想起读取安德斯Hejlsberg为约几个优点现有的架构带来了一个段落。但是,有什么副作用?难道真的是一个很好的权衡有非虚方法在默认情况下?

I am reminded of reading a paragraph from Anders Hejlsberg about several advantages the existing architecture is bringing out. But, what about side effects? Is it really a good trade-off to have non-virtual methods by default?

推荐答案

类应该的设计的继承,以便能够利用它的优势。有方法虚拟默认情况下,意味着在类中的每个功能可以拔出,取而代之的是另一种,这是不是一个真正的好东西。很多人甚至认为,类应该是密封默认情况下。

Classes should be designed for inheritance to be able to take advantage of it. Having methods virtual by default means that every function in the class can be plugged out and replaced by another, which is not really a good thing. Many people even believe that classes should have been sealed by default.

虚拟方法也有一个轻微的性能含义。这是不太可能是主要的原因,然而

virtual methods can also have a slight performance implication. This is not likely to be the primary reason, however.

这篇关于为什么C#实现方法作为非虚默认?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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