值类型如何从System.ValueType和System.Object继承 [英] How value types inherits from System.ValueType and System.Object

查看:115
本文介绍了值类型如何从System.ValueType和System.Object继承的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

值类型如何从

System.ValueType

System.Object

继承而值类型是struct,

,while value types are struct,
and don''t have inheritance?

推荐答案

所有类型都从System.Object继承,包括System.ValueType,所有值类型都从System.ValueType继承.

没有继承的值类型呢?它们有两种形式:普通的值形式"和盒装形式,它们确实支持继承. CLR的一个巧妙技巧是:只要您对值类型的任何方面都感兴趣,它就会为您带来盒装形式.例如,碰巧是您为System.Object变量分配值对象或使用GetType().换句话说:没有办法将纯"非盒装值类型用作类型.

请参阅: http://msdn.microsoft.com/en-us/library/yz2be5wk.aspx [^ ].

—SA
All types are inherited from System.Object, including System.ValueType, and all value types inherit from System.ValueType.

What about value types which do not have inheritance? They have two forms: a normal "value form" and a boxed form, which does support inheritance. The sly trick of CLR here is this: as soon as you are interested in any aspect of the value type as a type, it brings you a boxed form of it. For example, it happens is you assign a value object to System.Object variable or use GetType(). In other words: there are no ways to work with a "pure" non-boxed value type as a type.

Please see: http://msdn.microsoft.com/en-us/library/yz2be5wk.aspx[^].

—SA


引用该线程
http://stackoverflow.com/questions/4729094/value-types-inherit- from-system-object-why [ ^ ]

http://stackoverflow.com/questions/436211/is-everything-in- net-an-object/436246 [ ^ ]
Refer this thread
http://stackoverflow.com/questions/4729094/value-types-inherit-from-system-object-why[^]
and
http://stackoverflow.com/questions/436211/is-everything-in-net-an-object/436246[^]


这篇关于值类型如何从System.ValueType和System.Object继承的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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