由于的Int32是值类型为什么它继承的ToString()? [英] Since Int32 is a value type why does it inherit .ToString()?

查看:153
本文介绍了由于的Int32是值类型为什么它继承的ToString()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这些都是文档的ToString ()这促使了这个问题。他们指出:

These are the docs about .ToString() that has prompted this question. They state:

由于对象是在.NET中所有引用类型的基类   框架,这种行为[的ToString()被引用类型继承的不   重写ToString方法。

Because Object is the base class of all reference types in the .NET Framework, this behavior [.ToString()] is inherited by reference types that do not override the ToString method.

再进一步​​就可以进入状态:

Yet further on it goes to state:

例如,基本类型,如字符,的Int32和String提供的ToString实现

For example, the base types such as Char, Int32, and String provide ToString implementations

不过的Int32是结构,因此必须用值类型的。

However Int32 is a struct and hence must be a value type.

所以,这是怎么回事吗?是否的Int32实现它自己的ToString(),其中有无关对象?

So what's going on here? Does Int32 implement it's very own .ToString() which has nothing to do with Object?

推荐答案

的Int32是一个结构,因此值类型。 但是:

Int32 is a struct and therefore a value type. But:

System.Object
   System.ValueType
      System.Int32

的Int32源于System.ValueType这本身就来源于System.Object的。等瞧...

Int32 derives from System.ValueType and this itself derives from System.Object. Et voilà...

这篇关于由于的Int32是值类型为什么它继承的ToString()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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