不要值类型(整数,小数,布尔,等...)从Object继承? [英] Do value types (Integer, Decimal, Boolean, etc...) inherit from Object?

查看:182
本文介绍了不要值类型(整数,小数,布尔,等...)从Object继承?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

寻找澄清这...

我听说在.net'一切'从Object继承。我还听说,值类型和引用类型之间的区别是,引用类型的对象和值类型继承没有。

I've heard that 'everything' in .Net inherits from Object. I've also heard that the difference between value types and reference types is that reference types inherit from Object and value types do not.

我的理解是,一切是一个对象(继承自System.Object);但值类型和引用类型是简单地从彼此不同。值类型在堆栈上分配和引用类型得到一个指示器放置在指向上堆的地址堆栈。

My understanding was that everything was an object (inherits from System.Object); but value types and reference types were simply 'different' from one another. Value types are allocated on the stack and reference types get a 'pointer' placed on the Stack that points to an address on the Heap.

是它的要点?是什么让一个Integer值类型?这是在语言固有的东西?

Is that the gist of it? What makes an Integer a value type? That's something inherent in the language?

推荐答案

值类型,如的Int32 ,是结构。

在VS 2008的C#的帮助文件(因为我已经打开它)的结构:

From the VS 2008 C# help file (since I had it open) on structs:

一个结构不能从另一个结构或类继承,而且不能是类的基础。直接从System.ValueType,后者继承从System.Object所有结构继承。

A struct cannot inherit from another struct or class, and it cannot be the base of a class. All structs inherit directly from System.ValueType, which inherits from System.Object.

这篇关于不要值类型(整数,小数,布尔,等...)从Object继承?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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