为什么 .NET 中的每个类都继承自 Object? [英] Why does every class in .NET inherit from Object?

查看:52
本文介绍了为什么 .NET 中的每个类都继承自 Object?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不明白……

为什么他们需要一个共同的基础?

Why do they need a common base?

推荐答案

这个问题预设了一个错误.他们不需要一个共同的基本类型.这个选择并非出于必要.这是出于为客户提供最佳价值的愿望.

The question presupposes a falsehood. They don't need a common base type. This choice was not made out of necessity. It was made out of a desire to provide the best value for the customer.

在设计类型系统或其他任何与此相关的事情时,有时您会遇到决策点——您必须决定 X 或非 X.公共基类型或无公共基类型.当这种情况发生时,您会权衡 X 的成本和收益以确定净值,然后您权衡非 X 的成本和收益以确定净值,然后选择价值更高的那个.拥有共同基础类型的收益大于成本,由此产生的净收益大于没有共同基础类型的净收益.所以我们选择有一个共同的基类型.

When designing a type system, or anything else for that matter, sometimes you reach decision points -- you have to decide either X or not-X. Common base type or no common base type. When that happens you weigh up the costs and the benefits of X to determine the net value, and then you weigh up the costs and the benefits of not-X to determine the net value, and you go with the one that was higher value. The benefits of having a common base type outweigh the costs, and the net benefit thereby accrued is larger than the net benefit of having no common base type. So we choose to have a common base type.

这是一个相当模糊的答案.如果您想要更具体的答案,请尝试提出更具体的问题.

That's a pretty vague answer. If you want a more specific answer, try asking a more specific question.

这篇关于为什么 .NET 中的每个类都继承自 Object?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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